ReferenceError:无法findvariables:require at
我有一个关于使用Grunt的茉莉花的问题。 我不断收到错误,
ReferenceError:无法findvariables:require at
每当我运行我的茉莉花testing。 这是我的Gruntfile.js的jasmine条目:
jasmine: { js: { src: jsFiles, options: { specs: 'tests/*_spec.js', helpers: 'tests/helpers/*', vendor: 'vendor/*' } } },
我可以运行一个虚拟testing没有要求就好了,但是当我在一个testing中包括一个要求,像这样,我得到要求的错误。
var testD = require('../src/events_to_actions'); describe("events_to_actions", function() { it("is dummy test", function() { expect(true).toEqual(true); }); });
我有同样的问题。 只要安装这个节点包,并将这一行添加到您的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') } } },
@ user3741597build议的解决scheme可能会起作用,但这是一个倒退的解决scheme。
“grunt-template-jasmine-requirejs”是为AMD加载器RequireJS编写的。 另一方面,您正在使用CommonJS语法。 如果你想继续使用“grunt-contrib-jasmine”,那么你需要find一个CommonJS模板,否则使用Jasmine内置节点支持的信息,采取不同的方法。
这篇文章可能也有帮助。
从@ justin-helmer领导解决scheme,有一个模板允许你在grunt-contrib-jasmine中使用require调用(CommonJS语法):
https://www.npmjs.com/package/grunt-template-jasmine-nml
使用这个gruntconfiguration的一个例子:
jasmine: { options: { template: require('grunt-template-jasmine-nml'), helpers: 'spec/helpers/**/*.js', specs: 'spec/**/*.spec.js' } }