$ ( jQuery ) is undefined in jasmine

2,297 views
Skip to first unread message

Ra M

unread,
Apr 15, 2014, 9:06:24 PM4/15/14
to jasmi...@googlegroups.com
My first day with Jasmine and I cannot seem to solve the error.

Here is the error.
ReferenceError: $ is not defined
ReferenceError: $ is not defined
at Object.<anonymous> (file:///D:/NODEJS/NOTHING%20TO%20DO%20WITH%20NODEJS%20-%20jasmine-standalone-2.0.0/spec/RahulTest.js:27:5)
at attemptSync (file:///D:/NODEJS/NOTHING%20TO%20DO%20WITH%20NODEJS%20-%20jasmine-standalone-2.0.0/lib/jasmine-2.0.0/jasmine.js:1510:12)
at QueueRunner.run (file:///D:/NODEJS/NOTHING%20TO%20DO%20WITH%20NODEJS%20-%20jasmine-standalone-2.0.0/lib/jasmine-2.0.0/jasmine.js:1498:9)
at QueueRunner.execute (file:///D:/NODEJS/NOTHING%20TO%20DO%20WITH%20NODEJS%20-%20jasmine-standalone-2.0.0/lib/jasmine-2.0.0/jasmine.js:1485:10)
at Spec.Env.queueRunnerFactory (file:///D:/NODEJS/NOTHING%20TO%20DO%20WITH%20NODEJS%20-%20jasmine-standalone-2.0.0/lib/jasmine-2.0.0/jasmine.js:518:35)
at Spec.execute (file:///D:/NODEJS/NOTHING%20TO%20DO%20WITH%20NODEJS%20-%20jasmine-standalone-2.0.0/lib/jasmine-2.0.0/jasmine.js:306:10)
at Object.<anonymous> (file:///D:/NODEJS/NOTHING%20TO%20DO%20WITH%20NODEJS%20-%20jasmine-standalone-2.0.0/lib/jasmine-2.0.0/jasmine.js:1708:37)
at attemptAsync (file:///D:/NODEJS/NOTHING%20TO%20DO%20WITH%20NODEJS%20-%20jasmine-standalone-2.0.0/lib/jasmine-2.0.0/jasmine.js:1520:12)
at QueueRunner.run (file:///D:/NODEJS/NOTHING%20TO%20DO%20WITH%20NODEJS%20-%20jasmine-standalone-2.0.0/lib/jasmine-2.0.0/jasmine.js:1496:16)
at QueueRunner.execute (file:///D:/NODEJS/NOTHING%20TO%20DO%20WITH%20NODEJS%20-%20jasmine-standalone-2.0.0/lib/jasmine-2.0.0/jasmine.js:1485:10)


Here is the order of the libraries in the SpecRunner.html.
<link rel="shortcut icon" type="image/png" href="lib/jasmine-2.0.0/jasmine_favicon.png">
  <link rel="stylesheet" type="text/css" href="lib/jasmine-2.0.0/jasmine.css">

 <script type="text/javascript" src="lib/jasmine-2.0.0/jasmine.js"></script>
 <script type="text/javascript" src="lib/jasmine-2.0.0/jasmine-html.js"></script>
 <script type="text/javascript" src="lib/jasmine-2.0.0/boot.js"></script>
 <script type="text/javascript" href="//cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
 <!--<script type="text/javascript" src="lib/jasmine-2.0.0/jasmine-jquery.js"></script>-->


  <!-- include source files here... -->
  <script type="text/javascript" src="src/Player.js"></script>
  <script type="text/javascript" src="src/Song.js"></script>

  <!-- include spec files here... -->
  <script type="text/javascript" src="spec/SpecHelper.js"></script>
  <!-- <script type="text/javascript" src="spec/PlayerSpec.js"></script>  -->
  <script type="text/javascript" src="spec/RahulTest.js"></script>

 
Here is part of the spec
 it("tracks that the spy was called", function() {
    expect(foo.setBar).toHaveBeenCalled();
    foo.M1();
    $("#div1").html("<div>Yes</div>");
    
    expect(foo.M1).toHaveBeenCalled();
  });


The line in red is causing the error. Somehow, Jasmine cannot find jQuery ($).

Question
Usually we do $(document).ready(function(){ 
// This is where we access jQuery...
});

Is that needed in the spec ?

Any help is appreciated.

Thanks.
 



Greg Cobb

unread,
Apr 15, 2014, 10:14:12 PM4/15/14
to jasmi...@googlegroups.com
I believe support was added in this commit: https://github.com/pivotal/jasmine-gem/commit/29d77b253a53b35d82c578723b12ebae90a16e6f, however it looks like it hasn't be released yet. A workaround for now is to use a local version of jquery instead of one from a cdn.


--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at http://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/d/optout.

Ra M

unread,
Apr 16, 2014, 11:31:27 AM4/16/14
to jasmi...@googlegroups.com
Thank you Greg for the information.
Reply all
Reply to author
Forward
0 new messages