1

在 Ember.js 1.0.rc1 上使用 Konacha 进行集成测试时遇到问题。我的问题是所有测试都在呈现任何视图之前运行。有没有办法知道什么时候所有的东西都已经渲染了,而不需要手动超时?

规范助手:

//=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()

考试:

//=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
4

2 回答 2

4

也许将 Konacha 的重置功能设置为 noop 可以解决问题:

Konacha.reset = ->

默认情况下,它会在每次测试之前清除 body elmenet。您可以在 Jo Liss 的幻灯片中找到这个和其他有用的提示:http ://www.slideshare.net/jo_liss/testing-ember-apps

于 2013-03-28T11:07:27.307 回答
0

我有一个使用 Konacha 和最近构建的 Ember的示例应用程序。我发现将应用程序的就绪状态推迟到运行每个测试之后,然后提前就绪并等待新的应用程序就绪承诺得到解决,这很有帮助。这是来自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();
});
于 2013-03-28T11:23:37.700 回答