【发布时间】:2017-08-09 08:25:51
【问题描述】:
到目前为止,单元测试 Vuex 动作一直是一场噩梦,我似乎无法理解它真正在寻找什么。我正在关注https://vuex.vuejs.org/en/testing.html 并使用他们的操作助手功能。
我有一个简单的操作,可以将文本添加到按钮。
createButton({ commit, state }, payload) {
let btnString = '';
if (payload.hasCookie) {
btnString = 'Welcome back';
} else if (payload.isLoggedIn) {
btnString = 'Sign out';
} else {
btnString = 'Sign up';
}
commit({ type: 'CREATE_BUTTON_TEXT', text: btnText });
},
在我的测试中...
describe('Create Button Text', () => {
it('should render the buttons string ', (done) => {
const expectedString = 'Welcome back';
const mock = {
hasCookie: true,
isLoggedIn: false,
};
testAction(actions.createButton, mock, state, [
{ type: 'CREATE_BUTTON_TEXT', text: expectedString },
], done);
});
});
它正在返回 AssertionError: expected 'CREATE_BUTTON_TEXT' to equal { Object (type, text) }... 我没有正确提供预期的 text 和 expectedString 吗?非常感谢您就此事提供任何指导。
(按照文档中的建议使用 Mocha + Chai)。
【问题讨论】:
标签: unit-testing vue.js mocha.js chai vuex