diff --git a/packages/@react-facet/core/src/hooks/useFacetUnwrap.spec.tsx b/packages/@react-facet/core/src/hooks/useFacetUnwrap.spec.tsx index fe180d7..b3175e0 100644 --- a/packages/@react-facet/core/src/hooks/useFacetUnwrap.spec.tsx +++ b/packages/@react-facet/core/src/hooks/useFacetUnwrap.spec.tsx @@ -228,7 +228,7 @@ it('does not trigger a re-render when changing a facet from undefined to undefin }) it('supports custom equality checks', () => { - const value = {} + const value = { prop: 'initial' } const demoFacet = createFacet({ initialValue: value }) // Dummy equality check that always returns its not equal @@ -267,4 +267,18 @@ it('supports custom equality checks', () => { expect(check).toHaveBeenCalledTimes(1) // but the check should be executed expect(check).toHaveBeenCalledWith(value) // passing the value (which should be the same) expect(renderedMock).toHaveBeenCalledTimes(1) // and since the equality check always returns "false", we have a render + + jest.clearAllMocks() + + const newValue = { prop: 'new' } + + // If we update with a new object, + act(() => { + demoFacet.set(newValue) + }) + + expect(equalityCheck).toHaveBeenCalledTimes(0) // equality check was already initialized + expect(check).toHaveBeenCalledTimes(1) // but the check should be executed + expect(check).toHaveBeenCalledWith(newValue) // passing the new value + expect(renderedMock).toHaveBeenCalledTimes(1) // and since the equality check always returns "false", we have a render }) diff --git a/packages/@react-facet/core/src/hooks/useFacetUnwrap.ts b/packages/@react-facet/core/src/hooks/useFacetUnwrap.ts index 9e7faba..5b3e1c4 100644 --- a/packages/@react-facet/core/src/hooks/useFacetUnwrap.ts +++ b/packages/@react-facet/core/src/hooks/useFacetUnwrap.ts @@ -61,7 +61,7 @@ export function useFacetUnwrap( return { value } } - if (previousValue !== NO_VALUE && isEqual(previousValue)) { + if (previousValue !== NO_VALUE && isEqual(value)) { return previousState }