0

我的文件夹结构是这样的:

./package.json

src/Notification.js

测试/通知.js

文件通知.js

export default {
  template: '<div>{{message}}</div>',
  data() {
    return {
      message: 'Hello world'
    };
  }
};

文件通知.js

import Vue from 'vue';
import test from 'ava';
import Notification from '../src/Notification';
test('that it renders a notification', t => {
  new Vue(Notification).$mount();
});

我运行时出错:node_modules/.bin/ava

[Vue warn]: You are using the runtime-only build of Vue where the 
template compiler is not available. Either pre-compile the templates
into render functions, or use the compiler-incluided build. (found in
<Root>)
1failed
that it renders a notification
test finished without running any assertions

如果有人能告诉我出了什么问题并解释代码,我将非常感激。

4

2 回答 2

1

您的测试没有使用任何断言。你可能想在new Vue(Notification).$mount()返回值上声明一些东西。如果您只是确保它不会引发异常,您可以这样做t.notThrows(() => new Vue(Notification).$mount())

于 2017-07-16T13:21:03.353 回答
0

Vue 附带了几个版本,有些带有模板编译器,有些没有。你现在导入Vue的方式,没有包含模板编译器,所以Vue无法编译

template: '<div>{{message}}</div>',

尝试使用编译器导入 Vue 版本。

import Vue from "vue/dist/vue"
于 2017-07-13T16:46:36.687 回答