我有一个使用 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模板网!
在 javascript 认为文档“准备好"之前,如何让How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 认为文档“准备好
jasmine 运行和等待实际上是做什么的?What do jasmine runs and waitsFor actually do?(jasmine 运行和等待实际上是做什么的?)
如何提供模拟文件来更改 <input type='filHow to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模拟文件来更改 lt;input type=filegt; 的事
如何使用 Jasmine 对链式方法进行单元测试How to unit test a chained method using Jasmine(如何使用 Jasmine 对链式方法进行单元测试)
如何将 $rootScope 注入 AngularJS 单元测试?How do I inject $rootScope into an AngularJS unit test?(如何将 $rootScope 注入 AngularJS 单元测试?)
Jasmine - 如何监视函数中的函数调用?Jasmine - How to spy on a function call within a function?(Jasmine - 如何监视函数中的函数调用?)