Skip to content

Commit 34a3638

Browse files
committed
More tests.
1 parent aec4310 commit 34a3638

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
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",

test/index.test.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1+
/* eslint-disable no-underscore-dangle */
12
import _ from 'lodash';
23
import Vue from 'vue';
34
import test from 'ava';
5+
import nextTick from 'p-immediate';
46
import 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

1212
test('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
});

test/test.vue

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@ import _ from 'lodash';
1010
export 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

0 commit comments

Comments
 (0)