【发布时间】:2021-03-21 18:20:36
【问题描述】:
现在我正在观看关于使用 AVA 进行 Vue 测试的 Laracast 剧集。到目前为止,一切正常,但现在我发现了一个有趣的错误/问题。
我的 notification.js:
import test from 'ava';
import Notification from '../src/Notification';
test('that it renders a notification', t => {
//V2
let N = Vue.extend(Notification);
let string = 'Foobar';
string.trim();
let vm = new N({propsData:{message: string}}).$mount();
// V1
//let n = new Vue(Notification).$mount();
//t.truthy('unicorn'); // assertation needed, does not have any importance
//console.log(n.$el.innerHTML);
t.is(vm.$el.textContent,'Foobar');
});
导入的 Notification.js 如下所示:
export default{
template:'<div> {{ message }} </div>',
props:['message']
};
我收到以下错误消息:
that it renders a notification
test/notification.js:18
17:
18: t.is(vm.$el.textContent,'Foobar');
19: });
Difference:
- ' Foobar '
+ 'Foobar'
如您所见,AVA 认为消息中的字符串在 Foobar 之前和之后的两个空格不同。如您所见,我什至尝试修剪()字符串,但仍然发生错误。
有没有人知道这些空格是从哪里来的或者如何解决这个问题?
【问题讨论】:
-
你应该存储
trim()的结果,例如。string = string.trim()。你应该修剪vm.$el.textContent。
标签: javascript vue.js ava