T
TanStack10mo ago
eager-peach

rerender test

Hey there, currently the tanstack router does not seem to support testing rerender of hooks from: import { renderHook } from '@testing-library/react' I made a PR/fix https://github.com/TanStack/router/pull/2796 What is the correct process to get it approved? We have a repo with over 300000 lines of code and heavily depend on our unit/integration tests to pass, our hooks have some rather simple but powerful rerender tests since it can prove no state changes are done as part of a rerender - but tanstack router seems to block that untill this PR is merged...
it("should not trigger state change on rerender", () => {
const { result, rerender } = renderHook(() => {
return useYourHookToTest();
});

const initial = result.current;

rerender();

const updated = result.current;

expect(updated).toBeTruthy();
expect(updated).toBe(initial);
});
it("should not trigger state change on rerender", () => {
const { result, rerender } = renderHook(() => {
return useYourHookToTest();
});

const initial = result.current;

rerender();

const updated = result.current;

expect(updated).toBeTruthy();
expect(updated).toBe(initial);
});
GitHub
Allow rerender by mta-trackunit · Pull Request #2796 · TanStack/rou...
This changes so Tanstack router will support rerenders in tests using the renderHooks from testing library. import { renderHook } from '@testing-library/react' We heavily depend on ...
3 Replies
stormy-gold
stormy-gold10mo ago
I still don't understand what this re-render test does but we can't remove the memos as you saw, this kills all render optimizations
eager-peach
eager-peachOP10mo ago
The re-render test just checks that state does not change and effect other parts of the system - if all hooks can survive a rerender without sideeffects then you have a very stabile system.
stormy-gold
stormy-gold10mo ago
if you can find a way that does not disable the render optimizations we can go forward with this

Did you find this page helpful?