forked from vueuse/vueuse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.ts
67 lines (51 loc) · 1.74 KB
/
index.test.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { del, ref } from 'vue-demi'
import { reactivePick } from '.'
import { useSetup } from '../../.test'
describe('reactivePick', () => {
it('should work with variadic parameters', () => {
useSetup(() => {
const object = { a: 'a', b: 'b' }
const pickedObject = reactivePick(object, 'a', 'b')
expect(pickedObject.a).toEqual('a')
expect(pickedObject.b).toEqual('b')
expect((pickedObject as any).c).toBeUndefined()
object.a = 'foo'
expect(pickedObject.a).toEqual('foo')
})
})
it('should prefer the variadic overload over the array one', () => {
useSetup(() => {
const object = { a: 'a', b: 'b' }
const pickedObject = reactivePick(object, 'a')
expect(pickedObject.a).toEqual('a')
})
})
it('should work with non-ref key arrays', () => {
useSetup(() => {
const object = { a: 'a', b: 'b', c: 'c' }
const pickedObject = reactivePick(object, ['a', 'b'])
expect(pickedObject.a).toEqual('a')
expect(pickedObject.b).toEqual('b')
expect((pickedObject as any).c).toBeUndefined()
object.a = 'foo'
expect(pickedObject.a).toEqual('foo')
})
})
it('should work with ref key arrays', () => {
useSetup(() => {
const object = { a: 'a', b: 'b', c: 'c' }
const picks = ref(['a' as keyof typeof object])
const pickedObject = reactivePick(object, picks)
expect(pickedObject.a).toEqual('a')
expect(pickedObject.b).toBeUndefined()
object.a = 'foo'
expect(pickedObject.a).toEqual('foo')
picks.value.push('b')
expect(pickedObject.b).toEqual('b')
object.b = 'bar'
expect(pickedObject.b).toEqual('bar')
del(picks.value, 1)
expect(pickedObject.b).toBeUndefined()
})
})
})