Using jest and enzyme with next-multilingual
See original GitHub issueHow to enable this component for writing tests of app?
When using e.g. next-translate we made following test:
jest.config.js
import Enzyme from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import i18n_config from './i18n';
// enable next-translate for testing
global.i18nConfig = i18n_config;
// append the react enzyme adapter
Enzyme.configure({ adapter: new Adapter() });
test/examples/localeTest.js
import getT from 'next-translate/getT';
describe('Next translate', () => {
it('should match the translated string', async () => {
const t_en = await getT('en', 'common');
const t_de = await getT('de', 'common');
const text_en = t_en('Welcome');
const text_de = t_de('Welcome');
expect(text_en).toBe('Welcome');
expect(text_de).toBe('Willkommen');
});
});
Is there something similar to enable testing for own components with next-multilingual?
Thanks for your help in advance.
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Unit test Next.js with Jest and Enzyme | by Min | Medium
Simple setup unit test on Next.js + TypeScript with Jest and Enzyme. Install as dev dependency. First, you need to install Next.js here...
Read more >Testing React Components with Jest and Enzyme- In Depth
During the reading, I'll cover the next topics: Define the correct order of components' testing based on project structure; Find what to omit...
Read more >Setup and Write Unit test Next.js with Jest and Enzyme #nextjs
The next video will be with better audio and explanation. Thank you. You can find more configurations in this article by Miin Ancharee ......
Read more >Implementing basic Component tests using Jest and Enzyme
Jest is a testing library that can be used to test simple Javascript code or React components. This is done through simple API...
Read more >Setting up Jest with NextJS - TheRightChoyce
setup.js file allows any tests created in Jest to know about the Enzyme adapter, and then use Enzyme do its magic to allow...
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 Free
Top 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
Ok, I got the issue.
while working on my fork I had not set the fileExtension to load. Therefor the files could not be located.
But when using your original it is missing wile the babel on jest is running BEFORE initialization of
new Config
. ThereforeapplicationId
is not set.I solved that on my fork due to params opts from .babelrc
Yes, during compilation, the Babel plugin will inject the messages from all properties files associated with the file, based on naming conventions.