JSHint认为Jasmine函数是未定义的 [英] JSHint thinks Jasmine functions are undefined
问题描述
我有一个使用Karma + Jasmine和JSHint的Grunt设置。每当我在我的spec文件上运行JSHint时,我会遇到一系列未定义的错误,其中大部分是针对Jasmine的内置函数的。例如:
运行jshint:test(jshint)任务
js / main.spec .js
3 | describe(loadMatrix(),function(){
''describe'is not defined。
4 | it(如果没有arg,则不应指定值(){
''it'is not defined。
(我也从JS文件中得到了一些未定义的错误,这些错误是我的规范要测试的,但我不确定这是为什么,它可能是一个单独的问题。)
我的Karma配置文件中有框架:[jasmine]
,我没有为JSHint设置全局变量,我有一个 .jshintrc
文件,因为我在Grunt中配置它。我曾尝试在一点上在我的Gruntfile中添加Jasmine的函数作为JSHint全局变量,但将它们设置为 true
或 false
没有什么区别 - 当JSHint运行时错误仍然存在。
我错过了什么?我似乎无法做任何事情让JSHint跳过定义检查我的spec文件中的Jasmine函数。
MINOR CORRECTION - 在.jshintrc文件中应该有predef前缀。通过添加到 jshint
选项来修正在我的 Gruntfile.coffee
:
predef:[
在每个
之后的每个
之前的
之前描述
xdescribe
之前的
它
xit
it
注入
期望
spyOn
$ c
$ b $ pre $ predef:[
jasmine,
describe,
xdescribe,
before,
beforeEach,
after,
afterEach,
it,
xit,
it,
注入,
期望,
spyOn,
]
I've got a Grunt setup which uses Karma+Jasmine and JSHint. Whenever I run JSHint on my spec file, I get a series of "undefined" errors, most of which are for Jasmine's built-in functions. For example:
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.
(I also get some undefined errors for the variables and functions from the JS file that my spec is meant to test against, but I'm not sure why that is and it may be a separate issue.)
My Karma config file has frameworks: [ "jasmine" ]
in it, I don't have any globals set for JSHint, and I don't have a .jshintrc
file since I'm configuring it in Grunt. I did try adding Jasmine's functions as JSHint globals in my Gruntfile at one point, but setting them as either true
or false
didn't make a difference—the errors still persisted when JSHint ran.
What am I missing? I can't seem to do anything to get JSHint to skip definition checking for Jasmine's functions in my spec file.
MINOR CORRECTION - there should be "" around predef in the .jshintrc file.
Fixed by adding this to the jshint
options in my 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",
]
这篇关于JSHint认为Jasmine函数是未定义的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!