-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cacheable-section): stable references to avoid loops [LIBS-642] (#…
…1385) * fix(cacheable-sections): stable references * refactor: avoid needing eslint disable * chore: consistent test names
- Loading branch information
1 parent
a770597
commit 31562e9
Showing
5 changed files
with
232 additions
and
96 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
services/offline/src/lib/__tests__/cacheable-section-state.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { renderHook } from '@testing-library/react-hooks' | ||
import React, { FC } from 'react' | ||
import { mockOfflineInterface } from '../../utils/test-mocks' | ||
import { useCachedSection, useRecordingState } from '../cacheable-section-state' | ||
import { OfflineProvider } from '../offline-provider' | ||
|
||
const wrapper: FC = ({ children }) => ( | ||
<OfflineProvider offlineInterface={mockOfflineInterface}> | ||
{children} | ||
</OfflineProvider> | ||
) | ||
|
||
test('useRecordingState has stable references', () => { | ||
const { result, rerender } = renderHook(() => useRecordingState('one'), { | ||
wrapper, | ||
}) | ||
|
||
const origRecordingState = result.current.recordingState | ||
const origSetRecordingState = result.current.setRecordingState | ||
const origRemoveRecordingState = result.current.removeRecordingState | ||
|
||
rerender() | ||
|
||
expect(result.current.recordingState).toBe(origRecordingState) | ||
expect(result.current.setRecordingState).toBe(origSetRecordingState) | ||
expect(result.current.removeRecordingState).toBe(origRemoveRecordingState) | ||
}) | ||
|
||
test('useCachedSection has stable references', () => { | ||
const { result, rerender } = renderHook(() => useCachedSection('one'), { | ||
wrapper, | ||
}) | ||
|
||
const origIsCached = result.current.isCached | ||
const origLastUpdated = result.current.lastUpdated | ||
const origRemove = result.current.remove | ||
const origSyncCachedSections = result.current.syncCachedSections | ||
|
||
rerender() | ||
|
||
expect(result.current.isCached).toBe(origIsCached) | ||
expect(result.current.lastUpdated).toBe(origLastUpdated) | ||
expect(result.current.remove).toBe(origRemove) | ||
expect(result.current.syncCachedSections).toBe(origSyncCachedSections) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.