-
-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
…make sure it updates with useSnapshot
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,6 +319,7 @@ describe('proxyMap internal', () => { | |
).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('snapshot', () => { | ||
it('should error when trying to mutate a snapshot', () => { | ||
const state = proxyMap() | ||
|
@@ -375,3 +376,40 @@ describe('snapshot', () => { | |
expect(snap2.get('key1')).toBe('val1modified') | ||
}) | ||
}) | ||
|
||
describe('ui updates - useSnapshot', async () => { | ||
it('should update ui when calling has before and after deleting a key', async () => { | ||
const state = proxyMap() | ||
const TestComponent = () => { | ||
const snap = useSnapshot(state) | ||
|
||
return ( | ||
<> | ||
<p>has key1: {`${snap.has('key')}`}</p> | ||
<button onClick={() => state.set('key', 'value')}>set key</button> | ||
<button onClick={() => state.delete('key')}>delete key</button> | ||
</> | ||
) | ||
} | ||
|
||
const { getByText } = render( | ||
<StrictMode> | ||
<TestComponent /> | ||
</StrictMode>, | ||
) | ||
|
||
await waitFor(() => { | ||
getByText('has key1: false') | ||
}) | ||
|
||
fireEvent.click(getByText('set key')) | ||
await waitFor(() => { | ||
Check failure on line 406 in tests/proxyMap.test.tsx GitHub Actions / test_matrix (cjs, development)tests/proxyMap.test.tsx > ui updates - useSnapshot > should update ui when calling has before and after deleting a key
Check failure on line 406 in tests/proxyMap.test.tsx GitHub Actions / testtests/proxyMap.test.tsx > ui updates - useSnapshot > should update ui when calling has before and after deleting a key
Check failure on line 406 in tests/proxyMap.test.tsx GitHub Actions / test_matrix (esm, development)tests/proxyMap.test.tsx > ui updates - useSnapshot > should update ui when calling has before and after deleting a key
Check failure on line 406 in tests/proxyMap.test.tsx GitHub Actions / test_matrix (18.0.0)tests/proxyMap.test.tsx > ui updates - useSnapshot > should update ui when calling has before and after deleting a key
Check failure on line 406 in tests/proxyMap.test.tsx GitHub Actions / test_matrix (18.1.0)tests/proxyMap.test.tsx > ui updates - useSnapshot > should update ui when calling has before and after deleting a key
Check failure on line 406 in tests/proxyMap.test.tsx GitHub Actions / test_matrix (18.2.0)tests/proxyMap.test.tsx > ui updates - useSnapshot > should update ui when calling has before and after deleting a key
Check failure on line 406 in tests/proxyMap.test.tsx GitHub Actions / test_matrix (18.3.1)tests/proxyMap.test.tsx > ui updates - useSnapshot > should update ui when calling has before and after deleting a key
Check failure on line 406 in tests/proxyMap.test.tsx GitHub Actions / test_matrix (19.0.0-rc.0)tests/proxyMap.test.tsx > ui updates - useSnapshot > should update ui when calling has before and after deleting a key
Check failure on line 406 in tests/proxyMap.test.tsx GitHub Actions / test_matrix (19.0.0-rc-83825814-20241015)tests/proxyMap.test.tsx > ui updates - useSnapshot > should update ui when calling has before and after deleting a key
Check failure on line 406 in tests/proxyMap.test.tsx GitHub Actions / test_matrix (0.0.0-experimental-83825814-20241015)tests/proxyMap.test.tsx > ui updates - useSnapshot > should update ui when calling has before and after deleting a key
|
||
getByText('has key: true') | ||
}) | ||
|
||
fireEvent.click(getByText('delete key')) | ||
await waitFor(() => { | ||
getByText('has key: false') | ||
}) | ||
}) | ||
}) |