作者:好孩子_瑾马甲 | 来源:互联网 | 2023-01-20 15:56
我想测试具有嵌套菜单项的菜单.我希望能够模拟嵌套菜单项上的单击并查看是否调用了它的处理程序.我已经得到了没有嵌套菜单项的测试.
这是我正在尝试构建的测试的简单版本:
describe("menu", () => {
it("should click on nested nested menu items", () => {
const testOnClickSpy= Sinon.spy(() => {});
const compOnent= mount(
);
simulateEvent(component.find("#test"), "touchTap");
expect(component.find("#test").exists()).toBe(true); // Works fine.
expect(testOnClickSpy.callCount).toBe(1); // Works fine.
component.update(); // <--- Does not seem to do anything?
expect(component.find("#nested").exists()).toBe(true); // <--- Because this item cannot be found?
})
})
我用它simulateEvent
来模拟触摸式水龙头:
require("react-tap-event-plugin")();
function simulateEvent(wrappedTarget, eventType) {
const domNode = findDOMNode(wrappedTarget["node"]);
Simulate[eventType](domNode);
}
我使用的是React 15.6.1,material-ui 0.18.6,Enzyme 2.9.1 Jest 20.0.4
也许相关?React,Jest和Material-UI:如何测试在模态或弹出窗口中呈现的内容