这是我的Gruntfile jasmine配置任务。我通过供应商选项添加了jquery和jasmine-jquery。
jasmine: {
src: {
src: '<%= paths.dist %>/**/*.js',
options: {
specs: '<%= paths.tests %>/specs/*Spec.js',
helpers: '<%= paths.tests %>/helpers/*Helper.js',
outfile: '<%= paths.tests %>/_SpecRunner.html'
},
vendor: [
"<%= paths.bower %>/jquery/dist/jquery.js",
"<%= paths.bower %>/jasmine-jquery/lib/jasmine-jquery.js"
]
}
},
运行grunt后获取错误。看起来grunt-jasmine并不包括在任务中设置的供应商。
Running "jasmine:src" (jasmine) task
Testing jasmine specs via PhantomJS
>> ReferenceError: Can't find variable: jQuery at
>> dist/script.js:97
Core
X should return element
ReferenceError: Can't find variable: $ in file:///Users/jedrzejchalubek/Dropbox/Script/tests/specs/CoreSpec.js (line 6) (1)
ReferenceError: Can't find variable: $ in file:///Users/jedrzejchalubek/Dropbox/Script/tests/specs/CoreSpec.js (line 10) (2)
答案 0 :(得分:2)
哦,这是我的错。供应商需要在内部选项。任务配置应如下所示:
jasmine: {
src: {
src: '<%= paths.dist %>/**/*.js',
options: {
specs: '<%= paths.tests %>/specs/*Spec.js',
helpers: '<%= paths.tests %>/helpers/*Helper.js',
outfile: '<%= paths.tests %>/_SpecRunner.html',
vendor: [
"<%= paths.bower %>/jquery/dist/jquery.js",
"<%= paths.bower %>/jasmine-jquery/lib/jasmine-jquery.js"
]
},
}
}