Skip to content

Instantly share code, notes, and snippets.

@tirams
Forked from joneath/gist:1680082
Created February 15, 2012 07:18
Show Gist options
  • Save tirams/1834006 to your computer and use it in GitHub Desktop.
Save tirams/1834006 to your computer and use it in GitHub Desktop.
Basic Backbone View Jasmine Test
describe("NotesView", function() {
beforeEach(function() {
var notes = new NotesCollection();
spyOn(notes, "fetch");
var view = new NotesView({collection: notes});
});
describe("#initialize", function() {
it("should fetch the notes", function() {
expect(notes.fetch).toHaveBeenCalled();
});
describe("on notes fetch success", function() {
beforeEach(function() {
var request = mostRecentAjaxRequest();
request.response({
status: 200,
responseText: JSON.stringify([
{body: "Blog post #1", id: "1"}
])
});
});
it("should render the view", function() {
expect($(view.el).find(".post")).toHaveText("Blog post #1");
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment