This is now an actual repo:
/* | |
Load Sinon.JS in the SpecRunner: | |
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine.js"></script> | |
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine-html.js"></script> | |
<script type="text/javascript" src="sinon-1.0.0.js"></script> | |
<script type="text/javascript" src="sinon-ie-1.0.0.js"></script> | |
http://cjohansen.no/sinon/ | |
*/ |
namespace.views.MyWizard = Backbone.Views.extend({ | |
initialize: function() { | |
_.bindAll(this, 'render', 'wizardMethod'); | |
} | |
render: function() { | |
this.wizardMethod(); | |
return this; | |
}, |
Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications
like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.
open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl
You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html
beforeEach(function() { | |
var self = this; | |
//contacts | |
this.contacts = new App.Collections.Contacts(); | |
_.each(this.fixtures.Contacts.valid, function(c) { | |
self.contacts.add(new Contact(c)); | |
}); | |
this.contactsCollectionStub = | |
sinon.stub(App.Collections, 'Contacts') | |
.returns(this.contacts); |
// EntryPoint.js | |
define(function () { | |
return function EntryPoint(model1, model2) { | |
// stuff | |
}; | |
}); | |
// Model1.js | |
define(function () { | |
return function Model1() { |
////////////////////////// | |
// Pure "DI style" modules | |
// BackEndAnalytics.js | |
define(function () { | |
return function BackEndAnalytics() { | |
this.send = function () { }; | |
}; | |
}); |
//Simple d3.js barchart example to illustrate d3 selections | |
//other good related tutorials | |
//http://www.recursion.org/d3-for-mere-mortals/ | |
//http://mbostock.github.com/d3/tutorial/bar-1.html | |
var w = 300 | |
var h = 300 |
/*! ****************************** | |
Handlebars helpers | |
*******************************/ | |
// debug helper | |
// usage: {{debug}} or {{debug someValue}} | |
// from: @commondream (http://thinkvitamin.com/code/handlebars-js-part-3-tips-and-tricks/) | |
Handlebars.registerHelper("debug", function(optionalValue) { | |
console.log("Current Context"); | |
console.log("===================="); |
##Introduction
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,