问题描述
我有一个使用 Karma+Jasmine 和 JSHint 的 Grunt 设置.每当我在我的规范文件上运行 JSHint 时,我都会收到一系列未定义"错误,其中大部分是 Jasmine 的内置函数.例如:
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.
(我的规范要测试的 JS 文件中的变量和函数也有一些未定义的错误,但我不确定这是为什么,这可能是一个单独的问题.)
(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.)
我的 Karma 配置文件中有 frameworks: [ "jasmine" ],我没有为 JSHint 设置任何全局变量,也没有 .jshintrc 文件,因为我在 Grunt 中配置它.我曾尝试将 Jasmine 的函数作为 JSHint 全局变量添加到我的 Gruntfile 中,但是将它们设置为 true 或 false 并没有什么不同——错误仍然存在JSHint 跑了.
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.
我错过了什么?我似乎无法让 JSHint 在我的规范文件中跳过对 Jasmine 函数的定义检查.
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 - .jshintrc 文件中的 predef 周围应该有".
MINOR CORRECTION - there should be "" around predef in the .jshintrc file.
通过将其添加到我的 Gruntfile.coffee 中的 jshint 选项来修复:
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 函数未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)