Question

Having trouble doing integration testing with Konacha on Ember.js 1.0.rc1. My problem is that all tests run before any views are rendered. Is there a way to know when everything has been rendered without the need to do manual timeouts?

spec helper:

//=require sinon
//=require jquery
//=require jquery_ujs
//=require twitter/bootstrap
//=require handlebars
//=require ember
//=require ember-data
//=require_self
//=require icarium

window.lookupController = (name) ->
  Icarium.__container__.lookup('controller:' + name)

window.currentPath = ->
  lookupController('application').get('currentPath')

Ember.testing = true

Ember.run ->
  window.Icarium = Ember.Application.create()

the test:

//=require spec_helper

describe "user login", ->
  before (done) ->
    Ember.run ->
      Icarium.set 'ready', ->
        done()
      Icarium.initialize()

  afterEach ->
    Ember.run ->
      Icarium.reset()

  it "routes to login", ->
    Ember.run ->
      currentPath().should.eq "login"

  it "renders the login form", ->
    $('input[type=password]').should.exist
Was it helpful?

Solution

Maybe setting Konacha's reset function to a noop will do the trick:

Konacha.reset = ->

By default it clears the body elmenet before each test. You can find this and other useful tipps in Jo Liss' slides: http://www.slideshare.net/jo_liss/testing-ember-apps

OTHER TIPS

I've got an example app that uses Konacha and a very recent build of Ember. I've found it helpful to defer readiness of the app until each test is run, and then advance readiness and wait for the new App readiness promise to resolve. Here's code from test_helper.js:

//= require konacha_config
//= require sinon
//= require application

// Prevent the router from manipulating the browser's URL.
App.Router.reopen({location: 'none'});

//**** Global before / after ***

// Sinon fake server
var server;

// Stub out Konacha.reset()
Konacha.reset = Ember.K;

beforeEach(function(done) {
  // Fake XHR
  server = sinon.fakeServer.create();

  // Prevent automatic scheduling of runloops. For tests, we
  // want to have complete control of runloops.
  Ember.testing = true;

  Ember.run(function() {
    // Advance App readiness, which was deferred when the app
    // was created.
    //
    // This needs to be done here, after each iframe has been setup,
    // instead of in a global `before`.
    App.advanceReadiness();

    // When App readiness promise resolves, setup is complete
    App.then(function() {
      done();
    });
  });
});

afterEach(function() {
  // Reset App
  Ember.run(function() {
    App.reset();
  });

  // Restore XHR
  server.restore();
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top