Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/react-native-mmkv/src/__tests__/hooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ test('hooks update when the value is changed directly through the instance', ()
expect(result.current[0]).toStrictEqual('value 2')
})

test('hooks update when the instance is cleared', () => {
const { result } = renderHook(() => useMMKVString('string-key', mmkv))

act(() => {
result.current[1]('value')
})
expect(result.current[0]).toStrictEqual('value')

act(() => {
mmkv.clearAll()
})
expect(result.current[0]).toBeUndefined()
})

test('functional updates to hooks', () => {
const Component: React.FC = () => {
const [state, setState] = React.useState(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function createMockMMKV(
isReadOnly: false,
isEncrypted: false,
clearAll: () => {
const keysBefore = storage.keys()
const keysBefore = Array.from(storage.keys())
storage.clear()
// Notify all listeners for all keys that were cleared
for (const key of keysBefore) {
Expand Down
Loading