How to simulate a select

I’m trying to do some TDD with Elm. To test events, I do something like this:
|> Query.find [ Selector.id “someId” ]
|> Event.simulate Event.click
|> Event.expect SomeEvent

That works fine to simulate a click. But I can’t figure out how to test a html Select/option.

What I want to test: when user selects the last option from a select, should dispatch a specific message with a specific value.

Any tips?

In selects you get an input event as if the user had typed something. If you want to know which is the selected option you will have write an event decoder that checks for all the options to see if the selected one is the last one, or simply make a decoder that in case of a select returns index of the selected option and the option count.

Check this example:
https://ellie-app.com/9WjXB3WJQ9Ca1

Keep in mind that the options of a select have very different implementation in mobile than in the browser, so I don’t recommend looking at them as regular HTML entities.

Thanks a lot for your reply.

But I’m able to create a select and use it. My main problem is how to create an automated test to simulate this cenario using elm-test.

So with buttons I’m able to test them very easily with: Event.simulate Event.click

My problem is how to do something similar to this with a select.

Anyway, your example will help me with another problem I’m having, so thank you :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.