lundi 7 septembre 2020

An update to null inside a test was not wrapped in act(...)

When i run these Test i'm getting act(() => { problem.

If i comment the Test 2 it works so i'm not sure if this issue is in Test 2 or Test 1?

In most cases i've seen in google people use mock functions and then wrap it in the act but in my particular case i don't use functions i guess.

All test do pass, it just trows the error. So i'm guessing i'm just not placing properly the act function where it needs to be.

describe('Test', () => {
    it('Test 1', async () => {
        const { container } = render(<TestApp />)
        expect(await axe(container)).toHaveNoViolations()
    })

    it('Test 2', () => {
        const { getByTestId } = render(<TestApp />)
        const input = getByTestId(selectors.Input)
        user.type(input, '1231')
        expect(input).toHaveValue('1231')
    })
})
  console.error
    Warning: An update to null inside a test was not wrapped in act(...).
    
    When testing, code that causes React state updates should be wrapped into act(...):
    
    act(() => {
      /* fire events that update state */
    });
    /* assert on the output */
    
    This ensures that you're testing the behavior the user would see in the browser. Learn more at 
        in Unknown
        in ThemeProvider (created by ThemeProvider)
        in ThemeProvider (created by withProviders)
        in withProviders

Aucun commentaire:

Enregistrer un commentaire