Rerender stopped working on version 5.1.0
LuisaAPF opened this issue · 3 comments
Tests that use rerender
started failing after upgrading from 4.1.0 to 5.1.0. I understand the function behaviour changed recently, but this is not working for me:
it('should show MyComponent when show = true', async () => {
const { rerender } = render(MyComponent, {
props: {show: true}
})
expect(screen.queryByTestId('my_component')).toBeInTheDocument()
await rerender({props: {show: false}})
expect(screen.queryByTestId('my_component')).not.toBeInTheDocument()
})
Apologies, the docs PR detailing this change has not yet merged was only just merged today.
You now simply pass props to rerender
directly. You should be seeing a warning log to this effect.
- await rerender({props: {show: false}})
+ await rerender({show: false})
Thanks for your reply @mcous. I think I figured out the reason the tests broke. It wasn't because of the syntax (by the way, I didn't see any warnings, not sure if Vitest is suppressing them). It was because I was not using a reactive variable to hide my component, but instead a regular variable that depends on the prop and which was being assigned on mount.
Gotcha; that makes sense! rerender
in v4 destroyed and remounted the component, which would prevent you from seeing those sorts of reactivity bugs. That's why it was changed!