【发布时间】:2014-04-11 19:52:01
【问题描述】:
项目是:Backbone + Require + Underscore + Grunt + Grunt-Contrib-Jasmine + Grunt-Lib-PhantomJS
所以我一直在与两个严重的问题作斗争。我知道 phantomjs 运行正常等等,因为如果我包含我的应用程序 src 文件,我会遇到大量运行时错误。我什至已经正确地订购了部门,这样 Backbone 就不会因为 _ 没有被定义等等而吐槽。
1) 当我包含我的应用程序 src 时,我的所有源文件都会收到错误 can't find variable: define。我已经尝试将需求放入 src[] 而不是 vendor[],甚至尝试加载包含 deps 的 RequireJSConfig.js。
2) 关键是:我很确定我正确地指向了我的规范文件。如果我只是指向一个测试,它仍然显示No Specs Executed. Is there a configuration error? 在我的情况下,我只是指向我的UserModelUnitTest.js,这非常简单。它不执行。我要疯了!
规范 (UserModelUnitTest.js):
describe('User Model Unit Tests', function() {
var USER_MODEL,
USER_CLASS,
JSON_OBJ;
beforeEach(function() {
USER_CLASS = testr('models/user/User', {});
});
afterEach(function() {
USER_MODEL = null;
USER_CLASS = null;
JSON_OBJ = null;
});
describe('Given a json object', function() {
it('should create a valid User', function() {
JSON_OBJ = {"databaseId": 123456,"loginName": "god","firstName": "Jesus","lastName": "Christ","phone": "666-666-6666","email": "satan@hell.org","isoCountryCode": "US","languageCode": "en","roles" : ["SALES_REP"]};
USER_MODEL = new USER_CLASS(JSON_OBJ, { parse: true });
expect(USER_MODEL).not.toBe(null);
});
// etc...
});
})
这是我的目录结构
/project
- src
- main
+ test
+ js
+unit
UserModelUnitTest.js
这是我的 Gruntfile / Jasmine 配置
jasmine: {
test:{
vendor:[
'src/main/resources/js/lib-clean/jquery-2.1.0.js',
'src/main/resources/js/lib-clean/require-2.1.1.full.js',
'src/main/resources/js/lib-clean/underscore-1.5.2.min.js',
'src/main/resources/js/lib-clean/backbone-1.1.2.min.js'
],
src : [
// these all error like crazy. Can't find variable 'define' etc.
// 'src/main/**/*.js',
// 'src/main/**/**/*.js',
//'src/test/RequireJSConfig.js'
],
helpers : [
'src/test/js/helpers/dependencyHelper.js',
'src/test/js/helpers/errorHelper.js',
'src/test/js/helpers/requesetHelper.js',
'src/test/lib/testr.js',
// jasmine.js + jasmine-html.js etc
'src/test/lib/*.js',
// stubs
'src/test/js/stubs/*.js'
],
specs : [
'src/test/js/unit/UserModelUnitTest.js'
],
//specs : 'src/test/js/unit-headless.html',
timeout : 10000,
phantomjs : {
'ignore-ssl-errors' : true
}
}
},
【问题讨论】:
标签: javascript backbone.js gruntjs jasmine grunt-contrib-jasmine