我正在尝试设置一个示例 Jasmine 应用程序,但似乎我在包含 jQuery 时犯了一个错误。 我的 Gruntfile 看起来像这样:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
jasmine: {
src: 'src/**/*.js',
specs: 'spec/**/*.js',
options: {
vendor: 'bower_components/jquery/dist/jquery.js'
}
}
});
grunt.loadNpmTasks('grunt-jasmine-runner');
// Default task.
grunt.registerTask('default', 'jasmine');
};
我有一个规范文件,它在某处引用了 $
,它将失败并显示以下消息:
ReferenceError: Can't find variable: $
at http://127.0.0.1:8888/spec/PlayerSpec.js:14
at http://127.0.0.1:8888/node_modules/grunt-jasmine-runner/jasmine/lib/jasmine-core/jasmine.js:1035
at http://127.0.0.1:8888/node_modules/grunt-jasmine-runner/jasmine/lib/jasmine-core/jasmine.js:2034
at http://127.0.0.1:8888/node_modules/grunt-jasmine-runner/jasmine/lib/jasmine-core/jasmine.js:2024
jquery.js 的路径肯定是正确的。如果我删除 $
引用,规范就会通过。
最佳答案
你的问题的原因是 grunt-jasmine-runner
不支持 grunt
0.4+,并且它没有 vendor
选项.而是使用与 grunt
0.4+
grunt-contrib-jasmine
关于jquery - Jasmine 没有加载供应商选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28987107/