-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcomplex.spec.ts
39 lines (30 loc) · 1.28 KB
/
complex.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
import { describe, it, expect, beforeEach } from 'jest-without-globals'
import { getSnapshot } from 'mobx-state-tree'
import { persist } from '../src/index'
import { getItem } from './helpers'
import { ComplexUserStoreF, persistedComplexUserDataF } from './fixtures'
describe('persist complex types', () => {
beforeEach(() => window.localStorage.clear())
it('should persist an array', async () => {
const user = ComplexUserStoreF.create()
await persist('user', user)
user.addDog('Shadow') // fire action to trigger onSnapshot
expect(user.dogs).toStrictEqual(['Shadow'])
expect(getItem('user')).toStrictEqual(getSnapshot(user))
})
it('should persist a whitelisted array', async () => {
const user = ComplexUserStoreF.create()
await persist('user', user, {
whitelist: ['name', 'dogs']
})
user.addDog('Shadow') // fire action to trigger onSnapshot
expect(user.dogs).toStrictEqual(['Shadow'])
expect(getItem('user')).toStrictEqual(getSnapshot(user))
})
it('should load a persisted array', async () => {
window.localStorage.setItem('user', JSON.stringify(persistedComplexUserDataF))
const user = ComplexUserStoreF.create()
await persist('user', user)
expect(getSnapshot(user)).toStrictEqual(persistedComplexUserDataF)
})
})