Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using jest and enzyme with next-multilingual

See original GitHub issue

How to enable this component for writing tests of app?

When using e.g. next-translate we made following test:


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() });


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');

Is there something similar to enable testing for own components with next-multilingual?

Thanks for your help in advance.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

TomFreudenbergcommented, Feb 17, 2022

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. Therefore applicationId is not set.

I solved that on my fork due to params opts from .babelrc

nbouvrettecommented, Feb 17, 2022

Yes, during compilation, the Babel plugin will inject the messages from all properties files associated with the file, based on naming conventions.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found