next/config mock
See original GitHub issueI’m using storybook on a nextjs react project, and many of my components import
next/config on runtime, but I cannot seem to make it work in storybook/webpack.
being able to override imports with mocked files in .storybook would be nice. For this particular case.
For some reason setting: config.resolve.alias['next/config'] = path.join(__dirname, 'mocks/next/config.js');
in webpack.config.js doesn’t work.
I’ve tried to set resolve and alias in webpack.config, but doing import getConfig() from 'next/config';
node_modules always takes precedence.
I can do the work if anyone has an idea why this happens.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
Next.JS & JEST - publicRuntimeConfig undefined
I've tried using jest mock in test case file. jest.mock('next/config', () => () => ({ publicRuntimeConfig ...
Read more >publicRuntimeConfig undefined in test environment with Jest.
In my case, I mocked the next/config as shown: // jest.setup.js jest.mock('next/config' ...
Read more >Testing | Next.js
... app to load next.config.js and .env files in your test environment dir: '. ... Create the mock files referenced in the configuration...
Read more >Telerik React Report Viewer not working in NextJS
The NextJS application cannot render the page with the React Report Viewer . Instead of the report viewer, the page shows a stack...
Read more >Next.JS & JEST - publicRuntimeConfig undefined-Reactjs
It works for me calling jest.mock before the Component Test Case like you mentioned: jest.mock('next/config', () => () => ({ publicRuntimeConfig: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have used the following, which worked for me:
Hope this helps.
For those using a more recent version of Storybook the above solution goes in
.storybook/preview.js