Skip to content

Instantly share code, notes, and snippets.


Jim Newbery froots

View GitHub Profile
froots / gist:3164377
Created Jul 23, 2012 — forked from danscotton/gist:3164353
mocking with amd
View gist:3164377
// ----------------------------------------
// /path/to/dependency.js
define(function() {
return {
doSomethingWithIt: function() {
// blah
froots /
Created Jan 3, 2012 — forked from addyosmani/
Rough-work for Jasmine section of Backbone Fundamentals


One definition of unit testing is the process of taking the smallest piece of testable code in an application, isolating it from the remainder of your codebase and determining if it behaves exactly as expected. In this section, we'll be taking a look at how to unit test Backbone applications using a popular JavaScript testing framework called Jasmine.

For an application to be considered 'well'-tested, distinct functionality should ideally have its own separate unit tests where it's tested against the different conditions you expect it to work under. All tests must pass before functionality is considered 'complete'. This allows developers to both modify a unit of code and it's dependencies with a level of confidence about whether these changes have caused any breakage.

As a basic example of unit testing is where a developer may wish to assert whether passing specific values through to a sum function results in the correct output being returned. For an example more relevant to this book,