-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gatsby-script): Make load callback work when both load and error …
- Loading branch information
Showing
7 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...sts/development-runtime/cypress/integration/gatsby-script/gatsby-script-both-callbacks.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
describe(`both onLoad and onError callbacks are declared`, () => { | ||
beforeEach(() => { | ||
cy.visit(`/gatsby-script-both-callbacks/`).waitForRouteChange() | ||
}) | ||
|
||
it(`should execute the onLoad callback`, () => { | ||
cy.get(`[data-on-load-result=both-callbacks]`).should(`have.length`, 1) | ||
}) | ||
|
||
it(`should execute the onError callback`, () => { | ||
cy.get(`[data-on-error-result=both-callbacks]`).should(`have.length`, 1) | ||
}) | ||
}) |
30 changes: 30 additions & 0 deletions
30
e2e-tests/development-runtime/src/pages/gatsby-script-both-callbacks.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from "react" | ||
import { Script } from "gatsby" | ||
import { scripts } from "../../gatsby-script-scripts" | ||
import { onLoad, onError } from "../utils/gatsby-script-callbacks" | ||
|
||
const BothCallbacksPage = () => { | ||
return ( | ||
<main> | ||
<h1>Script component e2e test</h1> | ||
|
||
<Script | ||
src={scripts.marked} | ||
onLoad={() => { | ||
onLoad(`both-callbacks`) | ||
}} | ||
onError={() => {}} | ||
/> | ||
|
||
<Script | ||
src="/non-existent-script.js" | ||
onLoad={() => {}} | ||
onError={() => { | ||
onError(`both-callbacks`) | ||
}} | ||
/> | ||
</main> | ||
) | ||
} | ||
|
||
export default BothCallbacksPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
e2e-tests/production-runtime/cypress/integration/gatsby-script-both-callbacks.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
describe(`both onLoad and onError callbacks are declared`, () => { | ||
beforeEach(() => { | ||
cy.visit(`/gatsby-script-both-callbacks/`).waitForRouteChange() | ||
}) | ||
|
||
it(`should execute the onLoad callback`, () => { | ||
cy.get(`[data-on-load-result=both-callbacks]`).should(`have.length`, 1) | ||
}) | ||
|
||
it(`should execute the onError callback`, () => { | ||
cy.get(`[data-on-error-result=both-callbacks]`).should(`have.length`, 1) | ||
}) | ||
}) |
30 changes: 30 additions & 0 deletions
30
e2e-tests/production-runtime/src/pages/gatsby-script-both-callbacks.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from "react" | ||
import { Script } from "gatsby" | ||
import { scripts } from "../../gatsby-script-scripts" | ||
import { onLoad, onError } from "../utils/gatsby-script-callbacks" | ||
|
||
const BothCallbacksPage = () => { | ||
return ( | ||
<main> | ||
<h1>Script component e2e test</h1> | ||
|
||
<Script | ||
src={scripts.marked} | ||
onLoad={() => { | ||
onLoad(`both-callbacks`) | ||
}} | ||
onError={() => {}} | ||
/> | ||
|
||
<Script | ||
src="/non-existent-script.js" | ||
onLoad={() => {}} | ||
onError={() => { | ||
onError(`both-callbacks`) | ||
}} | ||
/> | ||
</main> | ||
) | ||
} | ||
|
||
export default BothCallbacksPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters