我想用于对我的组件ava
进行单元测试。Vue
现在我有一个非常简单的设置:
包.json
{
"name": "vue-testing",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"babel": {
"presets": [
"es2015"
]
},
"ava": {
"require": [
"babel-register",
"./test/helpers/setup-browser-env.js"
]
},
"devDependencies": {
"ava": "^0.18.1",
"babel-preset-es2015": "^6.24.1",
"babel-register": "^6.22.0",
"browser-env": "^2.0.21"
},
"dependencies": {
"vue": "^2.1.10"
}
}
./test/helpers/setup-browser-env.js
import browserEnv from 'browser-env';
browserEnv();
./test/Notification.js
import Vue from 'vue/dist/vue.js';
import test from 'ava';
import Notification from '../src/Notification';
let vm;
test.beforeEach(t => {
let N = Vue.extend(Notification);
vm = new N({ propsData: {
message: 'Foobar'
}}).$mount();
});
test('that it renders a notification', t => {
t.is(vm.$el.textContent, 'FOOBAR');
});
src/Notification.js
export default {
template: '<div><h1>{{ notification }}</h1></div>',
props: ['message'],
computed: {
notification() {
return this.message.toUpperCase();
}
}
};
当我运行时,ava
一切都按预期工作:1 passed
.
如果我可以使用以下组件语法,我会更高兴:
./src/Notification.vue
<template>
<div>
<h1>{{ notification }}</h1>
</div>
</template>
<script>
export default {
props: ['message'],
computed: {
notification() {
return this.message.toUpperCase();
}
}
}
</script>
但随后ava
会返回以下错误:
> 1 | <template>
| ^
2 | <div>
3 | <h1>{{ notification }}</h1>
4 | </div>
我不知道如何使这项工作,任何帮助将不胜感激!