/
index.test.ts
30 lines (29 loc) · 966 Bytes
/
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
import { ref } from 'vue-demi'
import { describe, expect, it } from 'vitest'
import { usePrecision } from '.'
describe('usePrecision', () => {
it('should be defined', () => {
expect(usePrecision).toBeDefined()
})
it('should work', () => {
const base = ref(45.125)
const result = usePrecision(base, 2)
expect(result.value).toBe(45.13)
base.value = -45.155
expect(result.value).toBe(-45.15)
})
it('out ceil should work', () => {
const base = ref(45.125)
const result = usePrecision(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 = usePrecision(base, 2, { math: 'floor' })
expect(result.value).toMatchInlineSnapshot('45.12')
base.value = -45.159
expect(result.value).toMatchInlineSnapshot('-45.16')
})
})