Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Kris Byrum
32,636 PointsSetting up JS Unit Testing with jQuery
I recently went though the JS Unit testing with Guil.
Great course, however I can't figure out how to test using jQuery.
Right now I'm not using a browser to do anything and it'd be great if I could do it all in the console.
i'm getting an error message that jQuery is not defined.
This is the framework for the .js file
(function($) { })(jQuery);
3 Answers
Jonathan Grieve
Treehouse Moderator 91,254 Points$(function() {
alert( 'JavaScript Loaded!' );
});
Try using this function to call the jQuery object.
Also make sure you;re correctly linking to the jquery source code. If you get an alert, you've verified that jQueryis correctly working. :-)
Kris Byrum
32,636 PointsI think I need to clarify.
I'm using jquery in my app. I'd like to test my functions without having to do anything in browser. So I'd like my testing to be done in console.
When I try to pass jQuery in the function, I get an error in my test saying jQuery was not defined.
I can't find anything online on how to properly make this work.
Seth Kroger
56,416 PointsThere's a package on NPM called mocha-jsdom you can try to help you inlcude jQuery in your tests. It has an example for jQuery in the middle of the page. You may also need to install jQuery with npm in your project so mocha can find it.