1
1
import { expect } from "chai" ;
2
2
import { mount } from "@vue/test-utils" ;
3
3
import Counter from "@/components/Counter.vue" ;
4
+ import { animationParser } from "@/components/optionsParser" ;
4
5
5
6
const factory = ( propsData , slots ) => {
6
7
return mount ( Counter , {
7
- propsData : { counterTick : { } , value : 50 , loading : false , animation : "default 100 200" , ...propsData } ,
8
+ propsData : {
9
+ counterTick : { } ,
10
+ value : 50 ,
11
+ loading : false ,
12
+ animation : animationParser ( "default 100 200" ) ,
13
+ ...propsData ,
14
+ } ,
8
15
slots,
9
16
} ) ;
10
17
} ;
@@ -26,7 +33,7 @@ global.cancelAnimationFrame = (id) => clearTimeout(id);
26
33
describe ( "[ Counter.vue ]" , ( ) => {
27
34
describe ( "#value" , async ( ) => {
28
35
it ( "renders the final value correctly" , ( done ) => {
29
- const counterWrapper = factory ( { value : 50 , animation : `default 0 0` } ) ;
36
+ const counterWrapper = factory ( { value : 50 , animation : animationParser ( `default 0 0` ) } ) ;
30
37
setTimeout ( ( ) => {
31
38
expect ( counterWrapper . element . textContent ) . to . equal ( "50" ) ;
32
39
} , 100 ) ;
@@ -42,7 +49,10 @@ describe("[ Counter.vue ]", () => {
42
49
const animation = { duration : 100 , delay : 1000 } ;
43
50
for ( const val of values ) {
44
51
const { value, count, start } = val ;
45
- const counterWrapper = factory ( { value, animation : `default ${ animation . duration } ${ animation . delay } ` } ) ;
52
+ const counterWrapper = factory ( {
53
+ value,
54
+ animation : animationParser ( `default ${ animation . duration } ${ animation . delay } ` ) ,
55
+ } ) ;
46
56
47
57
it ( "counts the decimals correctly" , ( ) => {
48
58
expect ( counterWrapper . vm . countDecimals ( ) ) . to . equal ( count ) ;
@@ -82,8 +92,8 @@ describe("[ Counter.vue ]", () => {
82
92
expect ( counterWrapper . vm . oneStepDifference ) . to . equal ( oneStepCountValue ) ;
83
93
} ) ;
84
94
85
- it ( "calculates the one step count value correctly with 0 duration" , ( ) => {
86
- counterWrapper . setProps ( { animation : "default 0 0" } ) ;
95
+ it ( "calculates the one step count value correctly with 0 duration" , async ( ) => {
96
+ await counterWrapper . setProps ( { animation : animationParser ( "default 0 0" ) } ) ;
87
97
const endValue = parseFloat ( value . toString ( ) . replace ( "," , "." ) ) ;
88
98
const startValue = 0 ;
89
99
const diff = Math . abs ( endValue - startValue ) ;
@@ -93,12 +103,12 @@ describe("[ Counter.vue ]", () => {
93
103
} ) ;
94
104
describe ( "#animation" , async ( ) => {
95
105
it ( "parses #animation prop correctly" , ( ) => {
96
- const counterWrapper = factory ( { value : 50 , animation : "default 200 300" } ) ;
106
+ const counterWrapper = factory ( { value : 50 , animation : animationParser ( "default 200 300" ) } ) ;
97
107
expect ( counterWrapper . vm . duration ) . to . equal ( 200 ) ;
98
108
expect ( counterWrapper . vm . delay ) . to . equal ( 300 ) ;
99
109
} ) ;
100
110
it ( "do not count the value before delay" , ( done ) => {
101
- const counterWrapper = factory ( { value : 50 , animation : "default 200 1000" } ) ;
111
+ const counterWrapper = factory ( { value : 50 , animation : animationParser ( "default 200 1000" ) } ) ;
102
112
expect ( counterWrapper . vm . currentValue ) . to . equal ( 0 ) ;
103
113
expect ( counterWrapper . element . textContent ) . to . equal ( "0" ) ;
104
114
setTimeout ( ( ) => {
0 commit comments