我有一个使用Karma + Jasmine和JSHint的Grunt设置.每当我在我的spec文件上运行JSHint时,我都会遇到一系列"未定义"的错误,其中大部分是Jasmine的内置函数.例如:
Running "jshint:test" (jshint) task
js/main.spec.js
3 |describe("loadMatrix()", function() {
^ 'describe' is not defined.
4 | it("should not assign a value if no arg is passed.", function() {
^ 'it' is not defined.
Run Code Online (Sandbox Code Playgroud)
(我也从我的规范要测试的JS文件中得到一些未定义的变量和函数错误,但我不确定为什么会这样,它可能是一个单独的问题.)
我的Karma配置文件包含frameworks: [ "jasmine" ]在其中,我没有为JSHint设置任何全局变量,.jshintrc因为我在Grunt中配置它,所以我没有文件.我确实尝试在我的Gruntfile中将Jasmine的函数添加为JSHint全局变量,但是将它们设置为true或者false没有区别 - 当JSHint运行时,错误仍然存在.
我错过了什么?我似乎无法做任何让JSHint在我的spec文件中跳过Jasmine函数的定义检查.
我一直在尝试很多东西,但是当我运行Karma时,我似乎无法加载.我已经尝试使用html2js和karma-jasmine-jquery-我向后者倾斜,但我会好起来用哪一个被我固定在DOM加载) -但据我可以告诉它没有得到装载并连接到DOM时我的测试运行.
我的目录结构非常简单:
img/
? mac.png
? link.png
? pocketwatch.png
js/
? spriteloader.js
? spriteloader.spec.js
karma/
? imagelist.fix.html
? karma.conf.js
Gruntfile.coffee
index.html
grunt.config.coffee
package.json
Run Code Online (Sandbox Code Playgroud)
这些是我安装的节点模块:
grunt 0.4.5
grunt-contrib-jshint 0.10.0
grunt-contrib-watch 0.6.1
grunt-karma 0.9.0
karma 0.12.23
karma-chrome-launcher 0.1.4
karma-firefox-launcher 0.1.3
karma-html2js-preprocessor": "^0.1.0",
karma-jasmine 0.2.0
karma-jasmine-jquery 0.1.1
karma-safari-launcher 0.1.1
karma-story-reporter 0.2.2
Run Code Online (Sandbox Code Playgroud)
这是我的karma.conf.js设置:
basePath: '../',
frameworks: ['jasmine-jquery', 'jasmine'],
files: [
// Source and spec files
{
pattern: 'js/*.js',
watched: true,
served: true,
included: true
},
// Fixtures …Run Code Online (Sandbox Code Playgroud)