what-input icon indicating copy to clipboard operation
what-input copied to clipboard

How to force input type in tests?

Open vysinsky opened this issue 7 years ago • 3 comments

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.

vysinsky avatar Jun 15 '17 06:06 vysinsky

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.

ten1seven avatar Jun 15 '17 13:06 ten1seven

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")
}));

greypants avatar Jan 24 '20 19:01 greypants

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.

mihkeleidast avatar Apr 28 '21 10:04 mihkeleidast