forked from vueuse/vueuse
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.test.ts
43 lines (42 loc) · 1.38 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
import { ref } from 'vue-demi'
import { useToFixed } from '.'
describe('useToFixed', () => {
it('should be defined', () => {
expect(useToFixed).toBeDefined()
})
it('should work', () => {
const base = ref(45.125)
const result = useToFixed(base, 2)
expect(result.value).toBe(45.13)
base.value = -45.155
expect(result.value).toBe(-45.15)
})
it('input string should work', () => {
const base = ref('45.125')
const result = useToFixed(base, 2)
expect(result.value).toBe(45.13)
base.value = '-45.155'
expect(result.value).toBe(-45.15)
})
it('out string should work', () => {
const base = ref('45.125')
const result = useToFixed(base, 3, { type: 'string' })
expect(result.value).toMatchInlineSnapshot('"45.125"')
base.value = '-45.15'
expect(result.value).toMatchInlineSnapshot('"-45.150"')
})
it('out ceil should work', () => {
const base = ref('45.121')
const result = useToFixed(base, 2, { math: 'ceil' })
expect(result.value).toMatchInlineSnapshot('45.13')
base.value = '-45.151'
expect(result.value).toMatchInlineSnapshot('-45.15')
})
it('out floor should work', () => {
const base = ref('45.129')
const result = useToFixed(base, 2, { math: 'floor' })
expect(result.value).toMatchInlineSnapshot('45.12')
base.value = '-45.159'
expect(result.value).toMatchInlineSnapshot('-45.16')
})
})