-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
index.test.ts
40 lines (36 loc) · 1.48 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
import { ref } from 'vue-demi'
import { useArrayJoin } from '../useArrayJoin'
describe('useArrayJoin', () => {
it('should be defined', () => {
expect(useArrayJoin).toBeDefined()
})
it('should work with array of refs', () => {
const item1 = ref('foo')
const item2 = ref(0)
const item3 = ref({ prop: 'val' })
const list = [item1, item2, item3]
const result = useArrayJoin(list)
expect(result.value).toBe('foo,0,[object Object]')
item1.value = 'bar'
expect(result.value).toBe('bar,0,[object Object]')
})
it('should work with reactive array', () => {
const list = ref(['string', 0, { prop: 'val' }, false, [1], [[2]], null, undefined, []])
const result = useArrayJoin(list)
expect(result.value).toBe('string,0,[object Object],false,1,2,,,')
list.value.push(true)
expect(result.value).toBe('string,0,[object Object],false,1,2,,,,true')
list.value = [null, 'string', undefined, 0, [], [1], [[2]], { prop: 'val' }]
expect(result.value).toBe(',string,,0,,1,2,[object Object]')
})
it('should work with reactive separator', () => {
const list = ref(['string', 0, { prop: 'val' }, [1], [[2]], null, undefined, []])
const separator = ref()
const result = useArrayJoin(list, separator)
expect(result.value).toBe('string,0,[object Object],1,2,,,')
separator.value = ''
expect(result.value).toBe('string0[object Object]12')
separator.value = '-'
expect(result.value).toBe('string-0-[object Object]-1-2---')
})
})