ReferenceError:运行JasmineHeadlessWebkit时找不到变量:$ [英] ReferenceError: Can't find variable: $ when running JasmineHeadlessWebkit
问题描述
我一直在试图找到一个答案,至少在最后两个小时没有运气。
I've been trying to find an answer to this at least for the last two hours without any luck. I hope someone here might be able to help.
我得到这个 ReferenceError:找不到变量:$ $ c $
I'm getting this ReferenceError: Can't find variable: $
when running my Jasmine specs using the JasmineHeadlessWebkit.
奇怪的是,这只发生在我说
The weird thing is, this only happens when I say
$ ->
game.init()
文件。
我可以使用 $
c> game.coffee 。例如:
I can use the $
without any problems further down game.coffee
. For example:
window.game =
init: ->
$('.gamelayer').hide()
$('#gamestartscreen').show()
这根本没有问题。
此外,测试在Chrome中运行正常。
Also, the tests work okay in Chrome.
所以,我假设这与jQuery没有及时加载,但我不知道为什么。
So, I'm assuming this has to do with jQuery not being loaded in time but I can't figure out why.
我在 specs / javascripts / helpers /
和中有jQuery jasmine.yml
我在 spec_files
和 src_files 之前提到
helpers
/ code>但是这似乎没有真正的区别。
I have jQuery in specs/javascripts/helpers/
and in jasmine.yml
i'm mentioning the helpers
before the spec_files
and src_files
but that doesn't seem to really make a difference.
所以,如果有人有任何想法,如何我可以确保jQuery是完全加载当Jasmine的规范运行时,我非常感谢任何帮助。
So, if anyone has any idea how I can make sure that jQuery is completely loaded when Jasmine's specs are run, I would really appreciate any help.
此外,如果您需要任何其他信息,请告诉我。
Also, please let me know if you need any additional information.
谢谢。
推荐答案
我也遇到了这个问题。我修改它通过更改我的jasmine.yml加载jquery之前,它加载的其余的javascript文件:
I ran into this problem also. I fixed it by changing my jasmine.yml to load jquery before it loads the rest of the javascript files:
src_files:
- public/js/jquery.js
- public/js/**/*.js
这篇关于ReferenceError:运行JasmineHeadlessWebkit时找不到变量:$的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!