I am working on a table which uses a tooltip in one of its columns.
<Tooltip
text={<MyCustomHoverComponent />}>
<Button label="a" icon />
</Tooltip>;
I want to be able to simulate a mouse over on the tooltip and look at the hover text:
test("Block - Master", () => {
const container = mount(
<Provider store={store}>
<EDesignerContainer activity={activity} name="VordruckContainer"/>
</Provider>
);
expect(container.find(".tooltip").length).toEqual(2); //ok
expect(container.find("div").length).toEqual(87); //ok
const el = container.find(".tooltip").at(0);
el.simulate("mouseenter");
expect(container.find(".hoverDiv").length).toEqual(1); //not OK!
});
But this does not seem to work. Obviously the “expect” is running before the callback is completed.
If I try with “flush promises” (it seems to be the recommended way of dealing with “waiting” issues https://stackoverflow.com/questions/49934975/how-to-simulate-mouse-over-event-on-a-div-using-enzyme-for-testing-a-react-appli ) then I also have no luck.
It seems like this tooltip is doing some async magic somewhere. Is it possible to intercept the hovered text in an enzyme test?
function flushPromises() {
return new Promise(setImmediate);
}
test("Block - Master", async () => {
const container = mount(
<Provider store={store}>
<EDesignerContainer activity={activity} name="VordruckContainer"/>
</Provider>
);
expect(container.find(".tooltip").length).toEqual(2); //ok
expect(container.find("div").length).toEqual(87); //ok
const el = container.find(".tooltip").at(0);
el.simulate("mouseenter");
await flushPromises();
expect(container.find(".hoverDiv").length).toEqual(1);//not OK!
});