4

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.

juliomalves
  • 42,130
  • 20
  • 150
  • 146
Efe Nadir
  • 43
  • 1
  • 6

0 Answers0