【发布时间】:2013-09-24 14:19:34
【问题描述】:
我是第一次尝试学习摩卡测试。我写了一个简单的测试脚本,比如:
describe('Analytics Test Suite', function(){
//http://emberjs.com/guides/testing/integration/
before(function() {
AS.rootElement = '#ember-application-container';
AS.setupForTesting();
AS.injectTestHelpers();
AS.reset();
});
describe('visit analytics index page', function(){
visit("/analytics").then(function() {
it('should return -1 when the value is not present', function(){
expect([1,2,3].indexOf(4)).to.be(-1);
expect([1,2,3].indexOf(0)).to.be(-1);
})
});
})
});
但是我得到这个 js 错误:
ReferenceError:访问未定义
但是如果我将代码修改为:
describe('Analytics Test Suite', function(){
AS.rootElement = '#ember-application-container';
AS.setupForTesting();
AS.injectTestHelpers();
AS.reset();
describe('visit analytics index page', function(){
visit("/analytics").then(function() {
it('should return -1 when the value is not present', function(){
expect([1,2,3].indexOf(4)).to.be(-1);
expect([1,2,3].indexOf(0)).to.be(-1);
})
});
})
});
我收到以下错误: TypeError: app._container_.lookup(...) 未定义
在第一个场景中,访问函数似乎丢失了,当将初始化代码放在之前的之外时,该函数得到了解决。但后来我得到类型错误,我认为它应该寻找 AS._container_lookup,但它正在寻找应用程序命名空间。我用的是ember调试版http://builds.emberjs.com/tags/v1.0.0/ember.js
您的帮助将不胜感激。我还添加了 jsbin http://jsbin.com/ILUbuy/2/。
谢谢, 深
更新 我解决了添加此适配器的问题:https://github.com/teddyzeenny/ember-mocha-adapter
【问题讨论】:
-
对于任何尝试设置相同设置的人,如果您使用的是
ember-mocha-adapter,请确保删除任何与mocha一起使用的done()语句。 -
请在回答您自己的问题时详细说明您的解决方案。 (是的,你可以这样做。)