Skip to content

Commit

Permalink
Add useDeepCompareMemo test
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinBirkhoff committed Jun 18, 2023
1 parent 67784ad commit 436be47
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/use-deep-compare/src/__tests__/useDeepCompareMemo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { renderHook } from '@testing-library/react'
import { useDeepCompareMemo } from '../index'

describe('useDeepCompareMemo', () => {
test('should return a memoized value', () => {
const factory = jest.fn(() => 'value')
let dependencies = [1, { foo: 'bar' }, [3, 4]]

const { result, rerender } = renderHook(() => useDeepCompareMemo(factory, dependencies))

expect(factory).toHaveBeenCalledTimes(1)
expect(result.current).toBe('value')

rerender()

expect(factory).toHaveBeenCalledTimes(1)
expect(result.current).toBe('value')

// Modify dependencies
dependencies = [2, { foo: 'baz' }, [5, 6]]
rerender()

expect(factory).toHaveBeenCalledTimes(2)
expect(result.current).toBe('value')
})
})

0 comments on commit 436be47

Please sign in to comment.