我有个关于用茉莉花和葛朗特的问题。我不断犯错误,
ReferenceError:找不到变量:要求
每次我做茉莉花测试。这是我的Gruntfile.js的茉莉花条目:
jasmine: {
js: {
src: jsFiles,
options: {
specs: 'tests/*_spec.js',
helpers: 'tests/helpers/*',
vendor: 'vendor/*'
}
}
},我可以在没有需求的情况下运行虚拟测试,但是当我在测试中包含一个需求时,就会得到需求错误。
var testD = require('../src/events_to_actions');
describe("events_to_actions", function() {
it("is dummy test", function() {
expect(true).toEqual(true);
});
});发布于 2014-06-15 04:01:09
我也有同样的问题。只需安装此节点包,并将此行添加到Gruntfile中,并要求重新开始工作。
https://github.com/cloudchen/grunt-template-jasmine-requirejs
jasmine: {
js: {
src: jsFiles,
options: {
specs: 'tests/*_spec.js',
helpers: 'tests/helpers/*',
vendor: 'vendor/*',
template: require('grunt-template-jasmine-requirejs')
}
}
},发布于 2015-12-12 22:33:20
@user3741597建议的解决方案可能有效,但这是一个有点向后的解决方案。
“咕噜-模板-茉莉花-需求”是为RequireJS编写的,这是一个AMD加载程序。另一方面,您正在使用CommonJS语法。如果您想继续使用“grunt- continue”,那么您需要找到一个CommonJS模板,或者使用Jasmine有内置的节点支持。的信息并采取不同的方法。
这个职位也可能有帮助。
发布于 2016-04-10 16:31:05
从@justin-helmer,的解决方案开始,有一个模板允许您使用require (CommonJS语法)和grunt-:
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'
}
}https://stackoverflow.com/questions/23449220
复制相似问题