Upgrade to Pro — share decks privately, control downloads, hide ads and more …

testing-ember-apps.pdf

 testing-ember-apps.pdf

Tom Kruijsen

March 12, 2014
Tweet

More Decks by Tom Kruijsen

Other Decks in Programming

Transcript

  1. #= 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()
  2. #= 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'! )
  3. #= 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()