Skip to content

Instantly share code, notes, and snippets.

Jim Newbery froots

Block or report user

Report or block froots

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@froots
froots / jasmine.md
Created Jan 3, 2012 — forked from addyosmani/jasmine.md
Rough-work for Jasmine section of Backbone Fundamentals
View jasmine.md

##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,

@froots
froots / gist:937431
Created Apr 22, 2011
Forrst comment in response to @sneeu's question: Curious to know if anyone’s used Backbone.js, or Spine, or something similar, and had any thoughts on advantages & disadvantages of each.
View gist:937431

I can only comment on Backbone.js, which as part of a 10-person team I'm currently using for a medium-sized single-page ('enterprisey') web application on the front-end. I would also say that the app is pretty much a read-only experience in that 99% of server requests are simple GET requests. There is a fair amount of data filtering and a bit of complexity in the view (dragging, scrolling, etc) which made us realise that using jQuery and a bunch of plugins alone would result in a big sloppy mess.

We were looking for something that could handle JavaScript routing and history management, as well providing a structure for separating data from the DOM and jQuery. In the future, we are also hoping to create versions for modern mobile browsers without having to re-write the entire application, for example by swapping out jQuery for Zepto.js on iOS devices. On top of all this we wanted something that would stand up to unit and functional testing without being a major pain in the backside (or backbone).

We looked a

@froots
froots / app.js
Created Feb 23, 2011
Simple test case demonstrating issue 228 for documentcloud/backbone
View app.js
var AppView = Backbone.View.extend({
display: function(text) {
$('#app').text(text);
}
});
var AppController = Backbone.Controller.extend({
@froots
froots / with-jasmine-sinon.js
Created Feb 14, 2011
An example Jasmine spec using jasmine-sinon to provide nicer matchers
View with-jasmine-sinon.js
it("should call the callback", function() {
var spy = sinon.spy();
doSomethingThenCallback(spy);
expect(spy).toHaveBeenCalled();
});
@froots
froots / without-jasmine-sinon.js
Created Feb 14, 2011
An example Jasmine spec using a Sinon.JS spy without the jasmine-sinon plugin
View without-jasmine-sinon.js
it("should call the callback", function() {
var spy = sinon.spy();
doSomethingThenCallback(spy);
expect(spy.called).toBeTruthy();
});
@froots
froots / example-gist.js
Created Dec 1, 2010
Example gist for testing import into web page
View example-gist.js
var myModule = (function(w) {
var internal = "I'm hidden",
privateMethod = function() {
return "Message is " + internal;
},
publicMethod = function() {
return privateMethod().replace('hidden', 'visible');
You can’t perform that action at this time.