lundi 4 juin 2018

Test that component rerendered?

I Use: react, react-testing-library, jest;

What I have is a component thar roughly does this kind of thing:

if(one condition) return <Component1 />
else return <Component2 />

The condition changes after clicking on some button. What I do in the test

 component = render(<Table />);
fireEvent(
            component.getByTestId("button-4286"),
            new MouseEvent("click", {
                bubbles: true, // click events must bubble for React to see it
                cancelable: true,
            })
        );

What happens: Through console.logging I see that component render method is called again, I se that condition is changed (in the console, when running tests).

But when I look at the output it's the same output, I expected it would render Component1, as condition changed, but no. I see that the condition has changed, but can't assert it.

I didn't recreate this, hoping maybe there is something obvious I miss and need to do, and this is the way it's expected to work. If it's not something expected I'll try to recreate this.

Aucun commentaire:

Enregistrer un commentaire