【发布时间】:2019-08-23 15:50:15
【问题描述】:
当我尝试测试将 CSS 样式“显示”更改为“无”的方法时,我的单元测试出现问题。测试失败并显示消息:
Expected: "display: none"
Received: undefined
在我的组件中我有方法:
closeCookie() {
document.querySelector(".cookies").style.display = "none";
}
Unit test
beforeEach(() => {
wrapper = shallowMount(Content);
});
it('change display for cookies class when click by the closeCookie', () => {
const stub = jest.fn();
wrapper.setMethods({ closeCookie: stub });
wrapper.find(".cross").trigger("click");
expect(wrapper.find(".cookies").attributes().style).toBe("display: none");
});
我在期待什么?
预期:“显示:无”
我收到了什么?
收到:未定义
比较两种不同类型的值。预期的字符串,但未定义。
我不确定,但我的班级似乎没有 css 样式“显示:无”。 如何测试?
【问题讨论】:
标签: unit-testing vue.js jestjs