Slide 1

Slide 1 text

Testing Ember Apps Tom Kruijsen Ember.js - 2014-03-12

Slide 2

Slide 2 text

Brightin

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Warning: blatant self- promotion

Slide 5

Slide 5 text

Appuccino

Slide 6

Slide 6 text

Some questions

Slide 7

Slide 7 text

Integration tests with QUnit

Slide 8

Slide 8 text

Unit tests?

Slide 9

Slide 9 text

Why QUnit?

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Konacha

Slide 12

Slide 12 text

Rails gem

Slide 13

Slide 13 text

Mocha & Chai

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

#= require 'sinon'! #= require 'application'! ! mocha.ui('bdd')! mocha.globals(['Ember', 'DS', 'Catstagram', 'MD5'])! mocha.timeout(5)! chai.Assertion.includeStack = true! ! ENV = {! TESTING: true! }! ! window.server = sinon.fakeServer.create()! ! window.testHelper =! lookup: (object, object_name) ->! name = object_name || "main"! Catstagram.__container__.lookup(object + ":" + name)! ! Catstagram.Router.reopen! location: 'none'! ! Konacha.reset = Ember.K! ! Catstagram.setupForTesting()! Catstagram.injectTestHelpers()! ! beforeEach ->! Ember.run ->! Catstagram.reset()! ! Ember.Test.adapter = Ember.Test.Adapter.create()

Slide 16

Slide 16 text

#= require spec_helper! ! describe "Cat", ->! it "is a DS.Model", ->! expect(Catstagram.Cat).to.exist! expect(DS.Model.detect(Catstagram.Cat)).to.exist! ! it "has a name", =>! Ember.run( ->! cat = testHelper.lookup('store').createRecord 'cat', name: 'Mimi'! expect(cat.get 'name').to.equal 'Mimi'! )

Slide 17

Slide 17 text

#= require 'spec_helper'! ! describe 'Cats page', ->! beforeEach ->! cat = Ember.Object.create! id: 1! name: 'Mimi'! ! stubStore = sinon.stub(testHelper.lookup('store'), 'find')! stubStore.withArgs('cat').returns([cat])! ! ! visit '/'! ! it 'shows the names of the cats', ->! expect($('li').text()).to.equal('Mimi')! ! it 'links to a cat page', ->! mock = sinon.mock(testHelper.lookup('route', 'cats_cat'))! mock.expects('setupController').once()! $('a').click()! mock.verify()

Slide 18

Slide 18 text

Mocha is nicer than QUnit

Slide 19

Slide 19 text

Use Sinon and mock a lot

Slide 20

Slide 20 text

How do you test your apps?

Slide 21

Slide 21 text

Testing Ember Apps Tom Kruijsen Ember.js - 2014-03-12