forked from streamich/react-use
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(streamich#785): update useStorage to use createGlobalState
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key This pull request depends on pull requests streamich#1021 streamich#979
- Loading branch information
Nathan Spaeth
committed
Mar 5, 2020
1 parent
6dc992c
commit 60aae0d
Showing
6 changed files
with
159 additions
and
35 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* eslint-disable */ | ||
import useStorage, { resetStorageState } from '../src/useStorage'; | ||
import 'jest-localstorage-mock'; | ||
import { renderHook, act } from '@testing-library/react-hooks'; | ||
|
||
describe(useStorage, () => { | ||
afterEach(() => { | ||
sessionStorage.clear(); | ||
localStorage.clear(); | ||
jest.clearAllMocks(); | ||
resetStorageState(); | ||
}); | ||
|
||
it('localStorage keys should not conflict with sessionStorage keys', () => { | ||
const { result: result1 } = renderHook(() => useStorage('localStorage', 'foo', 'baz', { raw: true })); | ||
const { result: result2 } = renderHook(() => useStorage('sessionStorage', 'foo', 'bar', { raw: true })); | ||
let [ state1, setState1 ] = result1.current; | ||
let [ state2, setState2 ] = result2.current; | ||
expect(state1 === 'baz'); | ||
expect(state2 === 'bar'); | ||
act(() => { | ||
setState1('baz-new'); | ||
}); | ||
[ state1, setState1 ] = result1.current; | ||
[ state2, setState2 ] = result2.current; | ||
expect(state1 === 'baz-new'); | ||
expect(state2 === 'bar'); | ||
act(() => { | ||
setState2('bar-new'); | ||
}); | ||
[ state1, setState1 ] = result1.current; | ||
[ state2, setState2 ] = result2.current; | ||
expect(state1 === 'baz-new'); | ||
expect(state2 === 'bar-new'); | ||
}); | ||
}); |