File tree 3 files changed +29
-6
lines changed
3 files changed +29
-6
lines changed Original file line number Diff line number Diff line change 38
38
"eslint-config-airbnb-base" : " ^11.1.0" ,
39
39
"eslint-plugin-html" : " ^2.0.0" ,
40
40
"eslint-plugin-import" : " ^2.2.0" ,
41
+ "p-immediate" : " ^2.1.0" ,
41
42
"vue" : " ^2.1.10" ,
42
43
"vue-loader" : " ^10.3.0" ,
43
44
"vue-template-compiler" : " ^2.1.10" ,
Original file line number Diff line number Diff line change
1
+ /* eslint-disable no-underscore-dangle */
1
2
import _ from 'lodash' ;
2
3
import Vue from 'vue' ;
3
4
import test from 'ava' ;
5
+ import nextTick from 'p-immediate' ;
4
6
import TestComponent from './test.vue' ;
5
7
6
- test ( 'works like it does in a browser' , ( t ) => {
7
- const Constructor = Vue . extend ( TestComponent ) ;
8
- const vm = new Constructor ( ) . $mount ( ) ;
9
- t . is ( vm . $el . querySelector ( 'h1' ) . textContent , 'Hello, World!' ) ;
8
+ test ( 'has a created hook' , ( t ) => {
9
+ t . true ( _ . isFunction ( TestComponent . created ) ) ;
10
10
} ) ;
11
11
12
12
test ( 'sets default data' , ( t ) => {
13
13
t . true ( _ . isFunction ( TestComponent . data ) ) ;
14
- t . deepEqual ( TestComponent . data ( ) , { name : 'World' } ) ;
14
+ t . deepEqual ( TestComponent . data ( ) , { name : 'Test' } ) ;
15
+ } ) ;
16
+
17
+ test ( 'renders the correct message' , async ( t ) => {
18
+ const Constructor = Vue . extend ( TestComponent ) ;
19
+ const vm = new Constructor ( ) . $mount ( ) ;
20
+ t . is ( vm . $el . querySelector ( 'h1' ) . textContent , 'Hello, World!' ) ;
21
+ // Update
22
+ vm . setName ( 'Foo' ) ;
23
+ await nextTick ( ) ;
24
+ t . is ( vm . $el . querySelector ( 'h1' ) . textContent , 'Hello, Foo!' ) ;
25
+ // Update directly 👻
26
+ vm . _data . name = 'Bar' ;
27
+ await nextTick ( ) ;
28
+ t . is ( vm . $el . querySelector ( 'h1' ) . textContent , 'Hello, Bar!' ) ;
15
29
} ) ;
Original file line number Diff line number Diff line change @@ -10,9 +10,17 @@ import _ from 'lodash';
10
10
export default {
11
11
data () {
12
12
return {
13
- name: _ .capitalize (' world ' ),
13
+ name: _ .capitalize (' test ' ),
14
14
};
15
15
},
16
+ created () {
17
+ this .name = ' World' ;
18
+ },
19
+ methods: {
20
+ setName (name ) {
21
+ this .name = name;
22
+ },
23
+ },
16
24
};
17
25
</script >
18
26
You can’t perform that action at this time.
0 commit comments