1 year ago

#75710

test-img

Efe Nadir

Content cannot translated and tests are failed on jest in next-i18next

I am using Next-i18next package for my localization purposes in my project.

I successfully rendered translated content on my UI. But when I try to test my content and text with enzym (shallow testing) and jest-dom, the tests are failed because the translated content does not render correctly.

I have tried various solutions:

No one is working for me.

My test file: form.test.tsx

describe("form", () => {
 it('should render the basic fields', () => {
    render(<MyFormComponent/>)
}
expect(
      screen.getByRole('textbox', { name: /First name/i })
    ).toBeInTheDocument();
})

 it('should match snapshot', () => {
    store = mockStore(initialState);
    const wrapper = shallow(<MyFormComponent/>)
}

I get this type of error from my failed tests:

TestingLibraryElementError: Unable to find a label with the text of: First Name

Because instead of 'First Name' string, the snapshot renders the 'firstName' key in translation json.

Any suggestion and solution will be welcome.

reactjs

jestjs

next.js

react-testing-library

next-i18next

0 Answers

Your Answer

Accepted video resources