-
-
Notifications
You must be signed in to change notification settings - Fork 981
/
rootState.spec.ts
48 lines (42 loc) 路 940 Bytes
/
rootState.spec.ts
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
import { createStore, getRootState } from '../src'
describe('Root State', () => {
const useA = createStore({
id: 'a',
state: () => ({ a: 'a' }),
})
const useB = createStore({
id: 'b',
state: () => ({ b: 'b' }),
})
it('works with no stores', () => {
expect(getRootState({})).toEqual({})
})
it('retrieves the root state of one store', () => {
const req = {}
useA(req)
expect(getRootState(req)).toEqual({
a: { a: 'a' },
})
})
it('does not mix up different requests', () => {
const req1 = {}
const req2 = {}
useA(req1)
useB(req2)
expect(getRootState(req1)).toEqual({
a: { a: 'a' },
})
expect(getRootState(req2)).toEqual({
b: { b: 'b' },
})
})
it('can hold multiple stores', () => {
const req1 = {}
useA(req1)
useB(req1)
expect(getRootState(req1)).toEqual({
a: { a: 'a' },
b: { b: 'b' },
})
})
})