Notes from the 'Testing Ember Apps' session
Part 1 Full stack integration tests
- 'Selenium for Rails'
- Performance issues are a problem
- Powerful but clunky
- Strategy: ONly test every model once DB-to-DOM, read and write
- Move finer-grained tests to client side
Part 2 Client side integration tests
The idea is to limit the architectural complexity. You have no back end. You have no DB. Test are run completely on the client.
- Rails gem pachaging
- Mocha.js testing framework +
Mocha + Chai
Mocha is a testing framework but it doesn't do assertions so you combine it with Chai. All test run in an i-frame by default and it's really fast.
It's very helpful to see it visually.
Why is it fast?
- No page loads
- 100% asynchronous
- No stack. The most expensive thing is the DOM manipulation that Ember does
Unit vs Integration
Lot of simple layers ==> integration tests win.
No 'official' support for testing. So we wing it!
AppRouter.reopen location: 'none' beforeEach: ->
Konacha by default clears out the body. Ember automatically schedules run loops
setTimeout. That's bad for reliable tests.
- goes out os sync with backend
- server-side computed attributes
- Write fixtures to DB
- Generate JSOn to fixtures.js. Load through RESTAdapter
- Covers models, serializers, adapters
- Easy to maintain
- Complex to set up
Q: with sinatra do you see opportunity for TTD
A: Not quite TDD but continuous. When working with Konacha I wrote tests as I went.
Q: Can you test views in isolation
A: it's really tricky to instantiate a view... It's too 'unit testy'. It might be possible
Q: A lot of bugs come from asynchronicity. Have you tried to test that specifically?
A: No I haven't. My hope is that a lot of these bugs dissapear. Mocha allows for asynchronous tests where you set a call back for when your test is complete.
See something wrong or got something to add/change? Fork this git repo and send me a pull request
If you particularly enjoy my work, I appreciate donations given with Gitcoin.co