通過偉大的yeoman generator-ember
(版本0.7.1)生成ember.js項目後,我嘗試使用集成的mocha
執行測試。通過ReferenceError測試Ember.JS應用程序失敗:未定義Ember
grunt test
或
npm test
標準的測試工作正常,但美國能源部不能引用灰燼項目。所以自己的模型試驗拋出
ReferenceError: Ember is not defined
at Context.<anonymous> (/home/lray/workspace/js/mediator/test/spec/source_model_test.js:9:9)
at Hook.Runnable.run (/home/lray/workspace/js/mediator/node_modules/mocha/lib/runnable.js:213:32)
at next (/home/lray/workspace/js/mediator/node_modules/mocha/lib/runner.js:243:10)
at Object._onImmediate (/home/lray/workspace/js/mediator/node_modules/mocha/lib/runner.js:254:5)
at processImmediate [as _immediateCallback] (timers.js:330:15)
這是上述試驗...
'use strict';
(function() {
describe('Mediator.Source (Model)', function() {
beforeEach(function() {
Ember.run(function() { Mediator.reset(); });
Ember.testing = true;
});
afterEach(function() {
Ember.testing = false;
});
describe('initialize like expected', function() {
it('should return the given parameters correctly', function(){
var oItem;
Ember.run(function() {
// Won't actually load until the end of the run-block.
oItem = Mediator.Source.find(1);
});
expect(oItem.get("id")).to.be.equal("myId");
expect(oItem.get("name")).to.be.equal("myName");
expect(oItem.additional).to.be.false();
})
})
});
})();
我package.json
小艾不變:
{
"name": "mediator",
"version": "0.0.1",
"dependencies": { },
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-coffee": "~0.7.0",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-compass": "~0.5.0",
"grunt-contrib-jshint": "~0.6.3",
"grunt-contrib-cssmin": "~0.6.0",
"grunt-contrib-connect": "~0.3.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-htmlmin": "~0.1.3",
"grunt-contrib-imagemin": "0.1.4",
"grunt-contrib-watch": "~0.5.2",
"grunt-rev": "~0.1.0",
"grunt-usemin": "~0.1.12",
"grunt-mocha": "~0.4.1",
"grunt-open": "~0.2.0",
"grunt-svgmin": "~0.2.0",
"grunt-concurrent": "~0.3.0",
"load-grunt-tasks": "~0.1.0",
"connect-livereload": "~0.2.0",
"grunt-ember-templates": "0.4.14",
"time-grunt": "~0.1.1",
"grunt-neuter": "~0.5.0",
"mocha": "~1.9.0",
"expect.js": "~0.2.0"
},
"scripts": {
"test": "mocha --recursive test/spec/*.js"
},
"engines": {
"node": ">=0.8.0"
}
}
更新:當添加require("ember");
到測試用例文件,npm test
抱怨
> [email protected] test /home/lray/workspace/js/mediator
> mocha --recursive test/spec/*.js
module.js:340
throw err;
^
Error: Cannot find module 'ember'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/lray/workspace/js/mediator/test/spec/source_model_test.js:4:1)
while grunt test
幸福地忽略了測試文件。
我是否必須以某種方式將連接安裝到Ember上的方式不同?如何做到這一點最好的方式?在此先感謝...
嗨@路易斯,thnx爲超高速響應。我早些時候嘗試過,但當grunt開始時忽略了測試用例,mocha抱怨沒有找到任何'ember'模塊。你有什麼不同的想法嗎? –