import { mount } from 'enzyme'; import React from 'react'; import { Subject } from 'rxjs'; import { useForceUpdate } from '..'; describe('useForceUpdate', () => { let renderCounts = 0; const TestComponent = ({ stream }: { stream: Subject }) => { const forceUpdate = useForceUpdate(); React.useEffect(() => { const subscription = stream.subscribe(() => forceUpdate()); return () => subscription.unsubscribe(); }); renderCounts += 1; return ; }; it('should rerender when the mutation stream changes', () => { const stream = new Subject(); const mounted = mount(); expect(renderCounts).toBe(1); stream.next(); expect(renderCounts).toBe(2); stream.next(); expect(renderCounts).toBe(3); mounted.unmount(); stream.next(); expect(renderCounts).toBe(3); }); });