ReferenceError: Can't find variable: require at
ReferenceError: Can't find variable: require at
我有一个关于在Grunt中使用jasmine的问题。总是出现错误
ReferenceError: Can't find variable: require at
当我运行茉莉测试时。这是我的茉莉花条目为我的Gruntfile.js:
jasmine: {
js: {
src: jsFiles,
options: {
specs: 'tests/*_spec.js',
helpers: 'tests/helpers/*',
vendor: 'vendor/*'
}
}
},
我可以在没有require的情况下运行一个虚拟测试,但是当我在测试中包含一个require时,就像这样,我得到了require错误。
var testD = require('../src/events_to_actions');
describe("events_to_actions", function() {
it("is dummy test", function() {
expect(true).toEqual(true);
});
});
我也遇到了同样的问题。只需安装这个节点包并将这一行添加到您的Gruntfile中,require就可以重新开始工作了。
https://github.com/cloudchen/grunt-template-jasmine-requirejsjasmine: {
js: {
src: jsFiles,
options: {
specs: 'tests/*_spec.js',
helpers: 'tests/helpers/*',
vendor: 'vendor/*',
template: require('grunt-template-jasmine-requirejs')
}
}
},
@user3741597建议的解决方案可能有效,但这是一个有点向后的解决方案。
"grunt-template-jasmine- requires "是为AMD的一个加载程序requires编写的。另一方面,您正在使用CommonJS语法。如果你想继续使用"grunt-contrib-jasmine",那么你需要找到一个CommonJS模板,或者使用Jasmine内置节点支持的信息并采取不同的方法。
这篇文章可能也有帮助。
从@justin-helmer的解决方案开始,有一个模板允许您使用grunt-contrib-jasmine:
使用require调用(CommonJS语法)https://www.npmjs.com/package/grunt-template-jasmine-nml一个grunt配置的例子:
jasmine: {
options: {
template: require('grunt-template-jasmine-nml'),
helpers: 'spec/helpers/**/*.js',
specs: 'spec/**/*.spec.js'
}
}
相关文章:
- 如何在 template.find(input:hidden[id='SOME VARIABLE']) 声明中使用动态
- IOS 上的 Safari 生成“ReferenceError: Ca ni n't find variable
- 不能调用JavaScript ReferenceError: Can't find variable
- safari ReferenceError: Can't find variable changestyledi
- ReferenceError: Can't find variable: google"检查是否未定义
- jQueryMobile pageInit, "Can't find variable?
- Getting ReferenceError: Can't find variable: require rea
- ReferenceError: Can't find variable: define at ..With
- ReferenceError: Can't find variable: require
- Phone Gap 'ReferenceError: Can't find variable: devi
- ReferenceError: Can't find variable: _e_0uWl - Browser &
- 参考错误:Can't find variable: bootbox
- ReferenceError: Can't find variable error
- 参考错误:Can't find variable: dataKeys
- 引用错误:Can't find variable
- ReferenceError: Can't find variable: require at
- JavaScript引用错误可以't find variable plus closure blues
- Browserify - Can't find variable: require
- 我如何修复这个AngularJS错误:Can't find variable: $interval
- ReferenceError: Can't find variable: jQuery with Polterg