Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to force input type in tests? #65

Open
vysinsky opened this issue Jun 15, 2017 · 3 comments
Open

How to force input type in tests? #65

vysinsky opened this issue Jun 15, 2017 · 3 comments

Comments

@vysinsky
Copy link

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.

@ten1seven
Copy link
Owner

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.

@greypants
Copy link

greypants commented Jan 24, 2020

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

@mihkeleidast
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants