lundi 25 novembre 2019

Rerendering with react-testing-library is not working

This is my test

    it('should run', async () => {
        const { container } = renderWithContainers(<Wrapper  />)

        window.innerHeight = 50
        await wait(() => fireEvent(window, new Event('resize')))

        expect(getByTestId(container, 'myComponent')).toHaveStyle(`position: relative`)
    })

This fails because the original position is fixed and im clearly using the container defined before the resize event fires...so how can I get it to "rerender" to use the updated container? in my code once it rerenders it then has a different position (just not in the test)

I've done this:

const { container, rerender } = renderWithContainers(<Wrapper  />)
window.innerHeight = 50
await wait(() => fireEvent(window, new Event('resize')))

rerender(<Wrapper />

but this breaks with invariant Violation: Could not find "store" react testing library but I have wrapped up all that store/provider logic inside renderWithContainers so how do I reuse that?

I want to do something like this: rerender(renderWithContainers(<Wrapper />)) but clearly that wont work

just to be ultra clear, I want to rerender my component after event listener has fired so I can see the updated component

Aucun commentaire:

Enregistrer un commentaire