File tree Expand file tree Collapse file tree 3 files changed +20
-7
lines changed
test/integration/script-loader Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -56,18 +56,19 @@ const loadScript = (props: ScriptProps): void => {
5656 const el = document . createElement ( 'script' )
5757
5858 const loadPromise = new Promise < void > ( ( resolve , reject ) => {
59- el . addEventListener ( 'load' , function ( ) {
59+ el . addEventListener ( 'load' , function ( e ) {
6060 resolve ( )
6161 if ( onLoad ) {
62- onLoad . call ( this )
62+ onLoad . call ( this , e )
6363 }
6464 } )
65- el . addEventListener ( 'error' , function ( ) {
66- reject ( )
67- if ( onError ) {
68- onError ( )
69- }
65+ el . addEventListener ( 'error' , function ( e ) {
66+ reject ( e )
7067 } )
68+ } ) . catch ( function ( e ) {
69+ if ( onError ) {
70+ onError ( e )
71+ }
7172 } )
7273
7374 if ( src ) {
Original file line number Diff line number Diff line change @@ -15,6 +15,14 @@ const Page = () => {
1515 src = "https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js?a=scriptLazyOnload"
1616 strategy = "lazyOnload"
1717 > </ Script >
18+ < Script
19+ src = "https://somebrokenlink.doesntexist"
20+ strategy = "lazyOnload"
21+ onError = { ( e ) => {
22+ console . log ( 'error' ) ;
23+ console . log ( e ) ;
24+ } }
25+ />
1826 < div > page3</ div >
1927 </ div >
2028 )
Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ describe('Script Loader', () => {
6969 await browser . waitForElementByCss ( '#onload-div' )
7070 await waitFor ( 1000 )
7171
72+ const logs = await browser . log ( 'browser' )
73+ const filteredLogs = logs . filter ( ( log ) => ! log . message . includes ( 'Failed to load resource' ) )
74+ expect ( filteredLogs . length ) . toBe ( 0 )
75+
7276 async function test ( id ) {
7377 const script = await browser . elementById ( id )
7478 const endScripts = await browser . elementsByCss (
You can’t perform that action at this time.
0 commit comments