Emberjs与konacha的集成测试



在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

也许将Konacha的重置函数设置为noop会奏效:

Konacha.reset = ->

默认情况下,它在每次测试之前清除body元素。你可以在Jo Liss的幻灯片中找到这些和其他有用的技巧:http://www.slideshare.net/jo_liss/testing-ember-apps

我有一个示例应用程序,使用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();
});

相关内容

  • 没有找到相关文章