Created
January 26, 2012 00:48
-
-
Save joneath/1680082 to your computer and use it in GitHub Desktop.
Basic Backbone View Jasmine Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
i'm pretty sure that you aren't scoping your Backbone objects properly; do these specs actually pass?
you'll probably want
above & outside the beforeEach() block.
then within the beforeEach(), you'd have the same assignment minus the "var" in front.
make sense? or am I off base/using an outdated Jasmine version?