-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[gatsby-link] Make it usable outside Gatsby #4892
Comments
Hmmm yeah. What do people normally do when testing components that rely on context? |
I had the same issue when testing Gatsby Link. This comment was useful to solve it. Hope this helps you :) |
Testing things with context? It really depends. I typically do one of two things:
Anyway, I'd really love for this for react-storybook too, so I can make storybook pages out of my components that use gatsby-link! |
Perhaps it'd be best to just create a context-less version? Can react-storybook do aliases? E.g. in there just create a component that wraps |
I have the same problem. Is it possible to provide a property which would render |
Old issues will be closed after 30 days of inactivity. This issue has been quiet for 20 days and is being marked as stale. Reply here or add the label "not stale" to keep this issue open! |
This issue is being closed due to inactivity. Is this a mistake? Please re-open this issue or create a new issue. |
Description
If you try to use
<Link />
outside of Gatsby (eg, when running tests), it fails because the component tree doesn't have the context injected by Gatsby:It'd be nice if
<Link />
will fallback to a common<a href=...>
in the absence of this context.Example
If you have a component (eg,
MyMenu.js
) that uses gatsby-link:And have a test file that renders with it (using Jest syntax here, but it doesn't matter what test harness you use):
You'll get⚠️
TypeError: Cannot read property 'history' of undefined
.Environment
npm list gatsby
): [email protected]gatsby --version
): n/aThe text was updated successfully, but these errors were encountered: