I'm looking to implement ava
for conducting unit tests on my Vue
components. Currently, I have a basic setup in place:
package.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();
}
}
};
Upon running ava
, all functions smoothly with an expected output of 1 passed
.
I am interested in utilizing the component syntax outlined below:
./src/Notification.vue
<template>
<div>
<h1>{{ notification }}</h1>
</div>
</template>
<script>
export default {
props: ['message'],
computed: {
notification() {
return this.message.toUpperCase();
}
}
}
</script>
However, attempting to run ava
results in the following error message:
> 1 | <template>
| ^
2 | <div>
3 | <h1>{{ notification }}</h1>
4 | </div>
I haven't been able to resolve this issue yet and any guidance would be highly appreciated!