Skip to content

Commit b722420

Browse files
committed
added tests units
1 parent 8c2125f commit b722420

15 files changed

+213
-94
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
docs
22
dist
3+
tests

tests/vue-number-component.custom.spec.ts renamed to tests/component/component.custom.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mount } from '@vue/test-utils'
2-
import VueNumber from '../src/component.vue'
2+
import VueNumber from '../../src/component.vue'
33

44
describe('VueNumber', () => {
55
test('should emit input event with the new value on input', async () => {
@@ -14,7 +14,6 @@ describe('VueNumber', () => {
1414
})
1515

1616
const input = wrapper.find('input')
17-
// input.element.value = '200'
1817

1918
await input.trigger('input')
2019

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { mount } from '@vue/test-utils'
2+
import VueNumber from '../../src/component.vue'
3+
4+
describe('VueNumber', () => {
5+
test('should emit input event with minimum fraction digits', async () => {
6+
const wrapper = mount(VueNumber, {
7+
propsData: {
8+
value: 123456.893,
9+
minimumFractionDigits: 2
10+
}
11+
})
12+
13+
const input = wrapper.find('input')
14+
15+
await input.trigger('input')
16+
17+
expect(wrapper.vm.maskedValue).toBe('123,456.893')
18+
19+
await input.trigger('blur')
20+
21+
expect(wrapper.vm.maskedValue).toBe('123,456.89')
22+
23+
input.element.value = '1234.5'
24+
25+
await input.trigger('input')
26+
27+
expect(wrapper.vm.maskedValue).toBe('1,234.5')
28+
29+
await input.trigger('blur')
30+
31+
expect(wrapper.vm.maskedValue).toBe('1,234.50')
32+
})
33+
})
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { mount } from '@vue/test-utils'
2+
import VueNumber from '../../src/component.vue'
3+
4+
describe('VueNumber', () => {
5+
test('should emit input event within range', async () => {
6+
const wrapper = mount(VueNumber, {
7+
propsData: {
8+
value: 1.893,
9+
min: 0,
10+
max: 50
11+
}
12+
})
13+
14+
const input = wrapper.find('input')
15+
16+
await input.trigger('blur')
17+
18+
expect(wrapper.vm.maskedValue).toBe('1.89')
19+
20+
input.element.value = '1234.568'
21+
22+
await input.trigger('blur')
23+
24+
expect(wrapper.vm.maskedValue).toBe('50')
25+
26+
input.element.value = '-1234.568'
27+
28+
await input.trigger('blur')
29+
30+
expect(wrapper.vm.maskedValue).toBe('0')
31+
32+
input.element.value = '12.568'
33+
34+
await input.trigger('blur')
35+
36+
expect(wrapper.vm.maskedValue).toBe('12.57')
37+
})
38+
})
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { mount } from '@vue/test-utils'
2+
import VueNumber from '../../src/component.vue'
3+
4+
describe('VueNumber', () => {
5+
test('should emit input event with reverse fill', async () => {
6+
const wrapper = mount(VueNumber, {
7+
propsData: {
8+
value: 123456.893,
9+
reverseFill: true
10+
}
11+
})
12+
13+
const input = wrapper.find('input')
14+
15+
await input.trigger('input')
16+
17+
expect(wrapper.vm.maskedValue).toBe('123,456.89')
18+
19+
await input.trigger('blur')
20+
21+
expect(wrapper.vm.maskedValue).toBe('123,456.89')
22+
23+
input.element.value = '1234568'
24+
25+
await input.trigger('input')
26+
27+
expect(wrapper.vm.maskedValue).toBe('12,345.68')
28+
29+
await input.trigger('blur')
30+
31+
expect(wrapper.vm.maskedValue).toBe('12,345.68')
32+
})
33+
})

tests/vue-number-component.spec.ts renamed to tests/component/component.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mount } from '@vue/test-utils'
2-
import VueNumber from '../src/component.vue'
2+
import VueNumber from '../../src/component.vue'
33

44
describe('VueNumber', () => {
55
test('should emit input event with the new value on input', async () => {
@@ -10,7 +10,6 @@ describe('VueNumber', () => {
1010
})
1111

1212
const input = wrapper.find('input')
13-
// input.element.value = '200'
1413

1514
await input.trigger('input')
1615

tests/number-format.spec.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/unit/number-format.custom.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ test('when the value is invalid with custom config', () => {
1616
expect(numberFormat.format('!@#$%^&*()')).toEqual('')
1717
})
1818
test('should return as follows', () => {
19-
expect(numberFormat.clean(true).unformat('')).toEqual('')
20-
expect(numberFormat.clean(true).unformat('foo')).toEqual('')
21-
expect(numberFormat.clean(true).unformat('-foo')).toEqual('')
22-
expect(numberFormat.clean(true).unformat('-fo.o-')).toEqual('')
23-
expect(numberFormat.clean(true).unformat('!@#$%^&*()')).toEqual('')
19+
expect(numberFormat.unformat('')).toEqual('')
20+
expect(numberFormat.unformat('foo')).toEqual('')
21+
expect(numberFormat.unformat('-foo')).toEqual('')
22+
expect(numberFormat.unformat('-fo.o-')).toEqual('')
23+
expect(numberFormat.unformat('!@#$%^&*()')).toEqual('')
2424
})
2525
})
2626
test('format when options are custom', () => {

tests/unit/number-format.custom.unformat.spec.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ test('unformat when options are default', () => {
88
nullValue: ''
99
})
1010
test('unformat string value', () => {
11-
expect(numberFormat.clean(true).unformat('')).toEqual('')
12-
expect(numberFormat.clean(true).unformat('0')).toEqual('0')
13-
expect(numberFormat.clean(true).unformat('0,')).toEqual('0')
14-
expect(numberFormat.clean(true).unformat('-0,0')).toEqual('0')
15-
expect(numberFormat.clean(true).unformat('0,10')).toEqual('0.1')
16-
expect(numberFormat.clean(true).unformat('0,0-')).toEqual('0')
17-
expect(numberFormat.clean(true).unformat('0,10-')).toEqual('-0.1')
18-
expect(numberFormat.clean(true).unformat('12.345,54921')).toEqual('12345.55')
19-
expect(numberFormat.clean(true).unformat('--12.345,12345')).toEqual('-12345.12')
20-
expect(numberFormat.clean(true).unformat('12.345.54321,12345')).toEqual('1234554321.12')
21-
expect(numberFormat.clean(true).unformat('-12.345,,54321-')).toEqual('-12345.54')
11+
expect(numberFormat.unformat('')).toEqual('')
12+
expect(numberFormat.unformat('0')).toEqual('0')
13+
expect(numberFormat.unformat('0,')).toEqual('0')
14+
expect(numberFormat.unformat('-0,0')).toEqual('0')
15+
expect(numberFormat.unformat('0,10')).toEqual('0.1')
16+
expect(numberFormat.unformat('0,0-')).toEqual('0')
17+
expect(numberFormat.unformat('0,10-')).toEqual('-0.1')
18+
expect(numberFormat.unformat('12.345,54921')).toEqual('12345.55')
19+
expect(numberFormat.unformat('--12.345,12345')).toEqual('-12345.12')
20+
expect(numberFormat.unformat('12.345.54321,12345')).toEqual('1234554321.12')
21+
expect(numberFormat.unformat('-12.345,,54321-')).toEqual('-12345.54')
2222
})
2323
test('unformat numerical value', () => {
24-
expect(numberFormat.clean(true).unformat(0)).toEqual('0')
25-
expect(numberFormat.clean(true).unformat(0)).toEqual('0')
26-
expect(numberFormat.clean(true).unformat(0.0)).toEqual('0')
27-
expect(numberFormat.clean(true).unformat(-0.1)).toEqual('-0.1')
28-
expect(numberFormat.clean(true).unformat(-0.0)).toEqual('0')
29-
expect(numberFormat.clean(true).unformat(0.1)).toEqual('0.1')
30-
expect(numberFormat.clean(true).unformat(12345.54921)).toEqual('12345.55')
31-
expect(numberFormat.clean(true).unformat(12345.12345)).toEqual('12345.12')
32-
expect(numberFormat.clean(true).unformat(12345.54321)).toEqual('12345.54')
33-
expect(numberFormat.clean(true).unformat(12345.54321)).toEqual('12345.54')
24+
expect(numberFormat.unformat(0)).toEqual('0')
25+
expect(numberFormat.unformat(0)).toEqual('0')
26+
expect(numberFormat.unformat(0.0)).toEqual('0')
27+
expect(numberFormat.unformat(-0.1)).toEqual('-0.1')
28+
expect(numberFormat.unformat(-0.0)).toEqual('0')
29+
expect(numberFormat.unformat(0.1)).toEqual('0.1')
30+
expect(numberFormat.unformat(12345.54921)).toEqual('12345.55')
31+
expect(numberFormat.unformat(12345.12345)).toEqual('12345.12')
32+
expect(numberFormat.unformat(12345.54321)).toEqual('12345.54')
33+
expect(numberFormat.unformat(12345.54321)).toEqual('12345.54')
3434
})
3535
})

tests/unit/number-format.default.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ test('when the value is invalid with default config', () => {
1010
expect(numberFormat.format('!@#$%^&*()')).toEqual('')
1111
})
1212
test('should return as follows', () => {
13-
expect(numberFormat.clean(true).format('')).toEqual('')
14-
expect(numberFormat.clean(true).format('foo')).toEqual('')
15-
expect(numberFormat.clean(true).format('-foo')).toEqual('')
16-
expect(numberFormat.clean(true).format('-fo,o-')).toEqual('')
17-
expect(numberFormat.clean(true).format('!@#$%^&*()')).toEqual('')
13+
expect(numberFormat.format('')).toEqual('')
14+
expect(numberFormat.format('foo')).toEqual('')
15+
expect(numberFormat.format('-foo')).toEqual('')
16+
expect(numberFormat.format('-fo,o-')).toEqual('')
17+
expect(numberFormat.format('!@#$%^&*()')).toEqual('')
1818
})
1919
test('should return as follows', () => {
2020
expect(numberFormat.unformat('')).toEqual('')

0 commit comments

Comments
 (0)