what-input
what-input copied to clipboard
How to force input type in tests?
Hello,
how can I force some input type in tests? I need to test my DropdownMenu which is behaving differently on touch (opens on click) and on mouse (opens on hover). I can run any JS from the test. Is there any way to trigger what-input detection?
Thank you.
Hi @vysinsky,
I've played around with using CasperJS to do testing. You can use things like mouse.move
and mouse.click
to simulate mouse events and then test the DOM to see if the event triggered what you wanted. Unfortunately CasperJS doesn't yet have touch event simulation.
If you're using Jest, i generally create a second *.touch.test.js
file where I mock whatInput.ask
to return touch
:
jest.mock("what-input", () => ({
ask: jest.fn(() => "touch")
}));
Triggering change events is also very difficult. I ended up ignoring the function passed into whatInput.registerOnChange
, because there is no simple way to trigger that in tests.