Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference jQuery #47

Closed
ohcibi opened this issue May 30, 2012 · 8 comments
Closed

undefined reference jQuery #47

ohcibi opened this issue May 30, 2012 · 8 comments

Comments

@ohcibi
Copy link

ohcibi commented May 30, 2012

I followed your instructions and wrote a simple failing test in coffeescript. The test fails as expected but i also get an "ReferenceError: jQuery is not defined at [object Object].cleanUp (http://localhost:3000/assets/jasmine-jquery-1.3.1.js?body=1:67:3)" error.

I then put #=require application in spec.js.coffee (which in fact requires a copy of jQuery for the application itself) and the error disappears. Is this as it should be or did i missed something in requiring jQuery?

@vladiim
Copy link

vladiim commented Jun 24, 2012

I had the same issue with #=require application in spec.js.coffee fixing it.

I am actually getting a ReferenceError on other resources also

When trying to go through Ryan Bate's RailsCast on Jasmine I get the following error:

ReferenceError: CreditCard is not defined
    at [object Object].<anonymous> (http://localhost:3000/assets/credit_card_spec.js?body=1:5:22)
    at [object Object].execute (http://localhost:3000/assets/jasmine.js?body=1:1024:15)
    at [object Object].next_ (http://localhost:3000/assets/jasmine.js?body=1:2025:31)
    at http://localhost:3000/assets/jasmine.js?body=1:2015:18

Although app/assets/javascipts/credit_card.js.coffee has the following:

CreditCard = cleanNumber: (number) ->
  number.replace /[- ]/g, ""

With #=require credit_card in either spec.js.coffee or credit_card_spec.js.coffee not having the same effect.

@ryanb
Copy link

ryanb commented Jun 27, 2012

CoffeeScript automatically scopes its files. Try setting this.CreditCard so it is available globally.

@vladiim
Copy link

vladiim commented Jun 27, 2012

Thanks Ryan! I had started doing stuff like window.CreditCard = class CreditCard to get around the issue which didn't feel right at all.

@ryanb
Copy link

ryanb commented Jun 27, 2012

Try class @CreditCard. I don't know if that's a best practice, but seems to work for me.

@vladiim
Copy link

vladiim commented Jun 27, 2012

Works a treat and much nicer syntax - thanks

@vladiim
Copy link

vladiim commented Jun 28, 2012

As a point of interest for anyone reading I've been going through the prags Coffeescipt Book and you can also do:

class CreditCard
  # code goes here

root = exports ? window # exports for node.js global
root.CreditCard = CreditCard

@bradphelan
Copy link
Owner

The solution to the OP's problem is a missing

spec/javascripts/spec.js.coffee

#= require jquery
#= require credit_card
#= require_tree .

As Ryan Bates quite rightly points out in his screencast

@ohcibi
Copy link
Author

ohcibi commented Jul 1, 2012

Shouldnt jasmine do this by itself? I saw that jasmine needs jquery-1.3 to make the results on the results page foldable. I dont even need jquery in these particular steps so i think jasmine should load its jquery-1.3 with noConflict. Not sure if this is a jasmine or a jasmine-rails or a jasminerice issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants