nucleartide / ember-elm

Write Elm in your Ember app
https://medium.com/@nucleartide/introducing-ember-elm-d47f2af73aff
Other
55 stars 7 forks source link

How to test? #18

Open ondrejsevcik opened 6 years ago

ondrejsevcik commented 6 years ago

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

nucleartide commented 6 years ago

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.

MattCheely commented 6 years ago

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.

ondrejsevcik commented 6 years ago

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?

nucleartide commented 6 years ago

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

ondrejsevcik commented 6 years ago

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