ember-elm icon indicating copy to clipboard operation
ember-elm copied to clipboard

How to test?

Open ondrejsevcik opened this issue 7 years ago • 5 comments

Hi, first of all, thanks for this awesome addon, it’s really nice to use.

I’ve been playing around with ember-elm and I came to the point where I would like to unit-test my elm code and I was wondering what’s your approach, do you use ember built in support for testing or you have custom scripts/tooling for testing elm code?

Thanks

ondrejsevcik avatar Nov 16 '17 22:11 ondrejsevcik

Hey @ondrejsevcik, thanks for the kind words! :)

I previously tried testing Elm code with Ember component tests (see here), but @MattCheely also mentioned using elm-test before on https://github.com/nucleartide/ember-elm/pull/16.

With Ember component tests though, you can potentially rewrite an Elm module as an Ember component, and still be able to use the test. This is what we tried at @Jet - we tested some vanilla JS components with Ember's test framework, with the thinking that the tests would still work when we migrated to any modern component lib.

So yeah, if you're thinking of component integration testing, then I would recommend using Ember component tests. But testing individual functions in Elm would be better done in elm-test.

nucleartide avatar Nov 16 '17 22:11 nucleartide

Much like @nucleartide suggested, we're using ember component tests to test the integrated components in Ember, which generally works well. IIRC, the only change we made to the existing tests when porting a component to elm was a very brief wait, to take into account Elm waiting to render in a requestAnimationFrame.

I also unit test things like serialization/deserialization and translation logic via elm-test. I didn't figure out a good way to integrate elm-test into Ember's testing pipeline though. Ultimately I just set up an elm-test folder inside of Ember's standard test folder, and we just run both the ember unit tests and elm-test via an npm run alias.

MattCheely avatar Nov 17 '17 04:11 MattCheely

When I do acceptance tests on a page with elm component, sometimes it fails and sometimes it passes. I guess it's because Ember run loop is not waiting for changes coming from Ember. Have you found an universal solution to this issue?

ondrejsevcik avatar Mar 13 '18 08:03 ondrejsevcik

@ondrejsevcik ember-native-dom-helpers has a waitFor helper that might help: https://github.com/cibernox/ember-native-dom-helpers#helpers

nucleartide avatar Mar 13 '18 21:03 nucleartide

Yeah, that would help, but it would be great to solve this in general to avoid using waitFor helper in every other test

ondrejsevcik avatar Mar 14 '18 09:03 ondrejsevcik