我有一个Grunt设置,它使用Karma+Jasmine和JSHint。每当我在我的规范文件上运行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.(我还从JS文件中得到了一些未定义的变量和函数错误,我的规范是针对JS文件进行测试的,但我不知道为什么会这样,这可能是一个单独的问题。)
我的Karma配置文件中有frameworks: [ "jasmine" ],我没有为JSHint设置任何全局文件,也没有一个.jshintrc文件,因为我在Grunt中配置它。我曾经尝试过在我的Gruntfile中将Jasmine的函数添加为JSHint全局函数,但是将它们设置为true或false并没有什么区别--当JSHint运行时,错误仍然持续存在。
我遗漏了什么?我似乎不能做任何事情让JSHint跳过定义检查,在我的规范文件中检查Jasmine的函数。
发布于 2014-10-01 02:55:56
小更正- .jshintrc文件中的predef周围应该有"“。
修正了将其添加到我的jshint中的Gruntfile.coffee选项
predef: [
"jasmine"
"describe"
"xdescribe"
"before"
"beforeEach"
"after"
"afterEach"
"it"
"xit"
"it"
"inject"
"expect"
"spyOn"
].jshintrc
"predef": [
"jasmine",
"describe",
"xdescribe",
"before",
"beforeEach",
"after",
"afterEach",
"it",
"xit",
"it",
"inject",
"expect",
"spyOn",
]发布于 2014-11-25 21:18:08
您只需将"jasmine": true添加到.jshintrc文件中即可。
发布于 2015-01-04 05:27:41
我在Gruntfile.js中修正了这一点,将jasmine: true添加到jshint任务的选项中:
jshint:
{
options:
{
...
node: true,
jasmine: true,
...
},
...
},和OP一样,我也不使用.jshintrc文件。
https://stackoverflow.com/questions/26091744
复制相似问题