JSHint 认为 Jasmine 函数未定义

JSHint thinks Jasmine functions are undefined(JSHint 认为 Jasmine 函数未定义)
本文介绍了JSHint 认为 Jasmine 函数未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个使用 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 中,但是将它们设置为 truefalse 并没有什么不同——错误仍然存在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 函数未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)