-
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): Improve error message when EnsureResources fails to ensu…
…re a resource (#21429) * fix(gatsby): Ensure that EnsureResources ensures resources * test * Throw error if the pageResource fails to load * fix lint * add jsx flag to allow test to pass * Update packages/gatsby/cache-dir/ensure-resources.js Co-Authored-By: Ward Peeters <ward@coding-tech.com> Co-authored-by: Ward Peeters <ward@coding-tech.com> Co-authored-by: GatsbyJS Bot <mathews.kyle+gatsbybot@gmail.com>
- Loading branch information
1 parent
678aa87
commit 7527993
Showing
3 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
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,33 @@ | ||
import React from "react" | ||
import EnsureResources from "../ensure-resources" | ||
import { render, getNodeText, cleanup } from "@testing-library/react" | ||
|
||
jest.mock(`../loader`, () => { | ||
return { | ||
loadPageSync(path: string): { loadPageSync: boolean; path: string } { | ||
return { loadPageSync: true, path } | ||
}, | ||
loadPage(path: string): Promise<{ loadPage: boolean; path: string }> { | ||
return Promise.resolve({ loadPage: true, path }) | ||
}, | ||
} | ||
}) | ||
|
||
afterAll(cleanup) | ||
|
||
describe(`EnsureResources`, () => { | ||
it(`loads pages synchronously`, () => { | ||
const location = { | ||
pathname: `/`, | ||
} | ||
const { container } = render( | ||
<EnsureResources location={location}> | ||
{(data: any): string => JSON.stringify(data.pageResources)} | ||
</EnsureResources> | ||
) | ||
|
||
expect(getNodeText(container)).toMatchInlineSnapshot( | ||
`"{\\"loadPageSync\\":true,\\"path\\":\\"/\\"}"` | ||
) | ||
}) | ||
}) |
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