4
我想測試我的菜單項,它具有嵌套的菜單項。我希望能夠模擬嵌套菜單項上的點擊並查看它是否被調用。我已經得到了沒有嵌套菜單項的測試。測試反應材料中的嵌套菜單項-ui菜單
這裏是測試我想建立一個簡單的版本:
describe("menu",() => {
it("should click on nested nested menu items",() => {
const testOnClickSpy = Sinon.spy(() => {});
const component = mount(
<MuiThemeProvider><Menu>
<MenuItem
primaryText={<span id="test">test</span>} onTouchTap={testOnClickSpy}
menuItems={ <MenuItem primaryText={<span id="nested">nested</span>} /> }/>
</Menu></MuiThemeProvider>
);
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);
}
我使用的陣營15.6。 1,material-ui 0.18.6,酶2.9.1 Jest 20.0.4
也許有關? React, Jest and Material-UI: How to test for content rendered in a modal or popover