File tree Expand file tree Collapse file tree 3 files changed +29
-6
lines changed
Expand file tree Collapse file tree 3 files changed +29
-6
lines changed Original file line number Diff line number Diff line change 3838 "eslint-config-airbnb-base" : " ^11.1.0" ,
3939 "eslint-plugin-html" : " ^2.0.0" ,
4040 "eslint-plugin-import" : " ^2.2.0" ,
41+ "p-immediate" : " ^2.1.0" ,
4142 "vue" : " ^2.1.10" ,
4243 "vue-loader" : " ^10.3.0" ,
4344 "vue-template-compiler" : " ^2.1.10" ,
Original file line number Diff line number Diff line change 1+ /* eslint-disable no-underscore-dangle */
12import _ from 'lodash' ;
23import Vue from 'vue' ;
34import test from 'ava' ;
5+ import nextTick from 'p-immediate' ;
46import TestComponent from './test.vue' ;
57
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 ) ) ;
1010} ) ;
1111
1212test ( 'sets default data' , ( t ) => {
1313 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!' ) ;
1529} ) ;
Original file line number Diff line number Diff line change @@ -10,9 +10,17 @@ import _ from 'lodash';
1010export default {
1111 data () {
1212 return {
13- name: _ .capitalize (' world ' ),
13+ name: _ .capitalize (' test ' ),
1414 };
1515 },
16+ created () {
17+ this .name = ' World' ;
18+ },
19+ methods: {
20+ setName (name ) {
21+ this .name = name;
22+ },
23+ },
1624};
1725 </script >
1826
You can’t perform that action at this time.
0 commit comments