我用Ember CLI进行了第一次验收测试 . 我使用Ember Mirage来模拟服务器 .
test('create file', function(assert){
visit('/login');
fillIn('input[name=username]', 'Joe');
fillIn('input[name=password]', 'foo');
click('button');
andThen(function() {
visit('/projects/files');
});
andThen(function(){
assert.ok(true);
})
});
测试成功运行,但它挂起,我收到以下错误
Uncaught(在promise中)错误:在Class.asyncStart(http:/)上的Object.stop(http:// localhost:4200 / assets / test-support.js:2469:10)的测试上下文之外调用stop() /lhosthost:4200/assets/vendor.js:49507:13)atyncStart(http:// localhost:4200 / assets / vendor.js:41446:44)at Object.async(http:// localhost:4200 / assets) /vendor.js:41460:7)at handle(http:// localhost:4200 / assets / vendor.js:61624:26)at handleMaybeThenable(http:// localhost:4200 / assets / vendor.js:61584:9) )at sealed(http:// localhost:4200 / assets / vendor.js:61597:7)密封(http:// localhost:4200 / assets / vendor.js:61536:11)
Ajax service
我使用ajax服务,它调用自定义api endpoints . 如您所见,它使用标准的JSONAPISerializer . 可能还是个问题?这是一个现有的应用程序,并没有简单的方法来关闭此服务,没有它测试 .
export default Ember.Service.extend({
// http://stackoverflow.com/questions/9705773/non-crud-actions-with-ember-data
call: function(method, type, id, action, hash = null){
var owner = Ember.getOwner(this);
var adapter = owner.lookup('adapter:application');
var url = adapter.buildURL(type, id) + '/' + action;
if (hash) {
hash.data = $.extend({}, hash);
}
return adapter.ajax(url, method, hash);
}
});
EDIT 1
我已经改变了测试,稍微打开了 ENV.APP.LOG_TRANSITIONS_INTERNAL 和 ENV.APP.LOG_TRANSITIONS 以查看更好的内容:
$.Velocity.mock = true
var done = assert.async();
visit('/login');
fillIn('input[name=username]', 'Joe');
fillIn('input[name=password]', 'foo');
click('button');
andThen(function() {
visit('/projects/files/new/overview');
setTimeout(function() {
assert.equal( find('.btn-primary').length, 2,"button was found" );
done();
}, 20000);
});
看起来登录工作正常,然后
转换#2:projects.files.new.overview.index:调用deserialize hook ember.debug.js:51061 Transition#2:projects.files.new.overview.index:调用afterModel hook ember.debug.js:51061 Transition #2:解决了目的地路线上的所有模型;完成过渡 . ember.debug.js:6520 generated - > controller:projects对象{fullName:“controller:projects”}
告诉我,过渡是好的,我可以在qunit的容器中看到新页面 .
有时候我也会收到
未捕获错误:断言失败:您已打开测试模式,禁用了运行循环的自动运行 . 您将需要在运行中包装具有异步副作用的任何代码