-
-
Notifications
You must be signed in to change notification settings - Fork 238
/
mapset.test.tsx
55 lines (45 loc) 路 1.36 KB
/
mapset.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { StrictMode } from 'react'
import { fireEvent, render } from '@testing-library/react'
import { proxy, useSnapshot } from 'valtio'
it('unsupported map', async () => {
const obj = proxy({ map: new Map([['count', 0]]) })
const Counter = () => {
const snap = useSnapshot(obj) as any
return (
<>
<div>count: {snap.map.get('count')}</div>
<button onClick={() => obj.map.set('count', 1)}>button</button>
</>
)
}
const { getByText, findByText } = render(
<StrictMode>
<Counter />
</StrictMode>
)
await findByText('count: 0')
fireEvent.click(getByText('button'))
await new Promise((resolve) => setTimeout(resolve, 10)) // FIXME better way?
expect(() => getByText('count: 1')).toThrow()
})
it('unsupported set', async () => {
const obj = proxy({ set: new Set([1, 2, 3]) })
const Counter = () => {
const snap = useSnapshot(obj) as any
return (
<>
<div>count: {[...snap.set].join(',')}</div>
<button onClick={() => obj.set.add(4)}>button</button>
</>
)
}
const { getByText, findByText } = render(
<StrictMode>
<Counter />
</StrictMode>
)
await findByText('count: 1,2,3')
fireEvent.click(getByText('button'))
await new Promise((resolve) => setTimeout(resolve, 10)) // FIXME better way?
expect(() => getByText('count: 1,2,3,4')).toThrow()
})