forked from vueuse/vueuse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.ts
55 lines (38 loc) · 1.07 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
import { ref } from 'vue-demi'
import { useAverage } from '.'
describe('useAverage', () => {
it('should be defined', () => {
expect(useAverage).toBeDefined()
})
it('should be the average', () => {
const arr = ref([1, 2, 3])
const v = useAverage(arr)
expect(v.value).toBe(2)
arr.value = [4, 5, 6]
expect(v.value).toBe(5)
})
it('should be the average when some are ref', () => {
const a = ref(2)
const arr = ref([1, a, 9])
const v = useAverage(arr)
expect(v.value).toBe(4)
a.value = 8
expect(v.value).toBe(6)
})
it('should be the average when some items are getter', () => {
const a = ref(1)
const arr = ref([1, () => a.value + 1, 9])
const v = useAverage(arr)
expect(v.value).toBe(4)
a.value = 7
expect(v.value).toBe(6)
})
it('should be the average when the array is a getter', () => {
const arr = ref([1, 2, 3])
const last = ref(0)
const v = useAverage(() => arr.value.concat(last.value))
expect(v.value).toBe(1.5)
last.value = 10
expect(v.value).toBe(4)
})
})