-
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Allow usage outside of Next.js (e.g. Jest and Storybook) (#76)
* fix: Allow usage outside of Next.js (e.g. Jest and Storybook) * Wording
- Loading branch information
Showing
10 changed files
with
1,212 additions
and
19 deletions.
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
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,5 @@ | ||
// Used by Jest | ||
|
||
module.exports = { | ||
presets: ['next/babel'] | ||
}; |
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,7 @@ | ||
{ | ||
"testEnvironment": "jsdom", | ||
"rootDir": "../", | ||
"transform": { | ||
"\\.tsx$": ["babel-jest", { "configFile": "./config/babel.config.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
30 changes: 30 additions & 0 deletions
30
packages/example-advanced/src/components/Navigation.spec.tsx
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 @@ | ||
// @ts-ignore | ||
|
||
import {render} from '@testing-library/react'; | ||
import {pick} from 'lodash'; | ||
import {NextIntlProvider} from 'next-intl'; | ||
import messages from '../../messages/en.json'; | ||
import Navigation from './Navigation'; | ||
|
||
// If the tested component uses features from Next.js, you have to mock them. | ||
// Note that next-intl only has an optional dependency on Next.js. | ||
jest.mock('next/router', () => ({ | ||
useRouter() { | ||
return { | ||
route: '/', | ||
locale: 'en', | ||
locales: ['en', 'de'] | ||
}; | ||
} | ||
})); | ||
|
||
it('renders', () => { | ||
render( | ||
<NextIntlProvider | ||
locale="en" | ||
messages={pick(messages, Navigation.messages)} | ||
> | ||
<Navigation /> | ||
</NextIntlProvider> | ||
); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
}, | ||
"include": [ | ||
"next-env.d.ts", | ||
"**/*.js", | ||
"**/*.ts", | ||
"**/*.tsx" | ||
], | ||
|
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
Oops, something went wrong.
7c6925b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: