Emberjs与konacha的集成测试
Emberjs integration testing with 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();
});
相关文章:
- Meteor集成测试,在velocity'她的镜子上有茉莉花
- 单页应用程序的javascript集成测试
- Javascript代码集成测试
- Javascript 客户端框架与 Rails JSON API - 如何进行集成测试
- Dropzone.js :在 php-webdriver 集成测试中上传文件而不带浏览对话框
- 如何对(Angularjs)Web应用程序进行集成测试
- 复杂的CSS选择器,用于使用webdriverjs进行集成测试
- Ember.js:坚持初始集成测试
- 余烬集成测试错误.处理异步副作用
- 如何在集成测试中访问ember数据存储实例
- 在ember.js/QUnit集成测试中,如何让QUnit在断言之前等待模型完成加载
- Ember集成测试,如何使用wait构建自定义Helper
- 访问Jasmine中的Meteor模板帮助程序函数进行集成测试
- 如何使用npm库提供异步集成测试
- 可以在集成测试中的规格之间重新启动浏览器吗
- Javascript集成测试框架
- 集成测试JavaScript与本地存储交互的正确方法是什么
- Ember集成测试:承诺在呈现之前被拒绝
- Angular.js单元/集成测试-触发链接功能
- Emberjs与konacha的集成测试