Created
June 5, 2012 17:30
-
-
Save juanghurtado/2876409 to your computer and use it in GitHub Desktop.
Jasmine Sinon Backbone
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
define( | |
[ | |
"backbone", "marionette", "jquery", | |
"modules/app/app", | |
"text!modules/index/templates/weather.html", | |
"text!modules/index/templates/multiple.html", | |
"text!modules/index/templates/loading.html" | |
], | |
function(Backbone, Marionette, $, App, weatherTpl, multipleTpl, loadingTpl) { | |
var module = App.module('Index'); | |
// Views and Model definitions.... | |
// This callback is executed when "Module.start()" | |
module.addInitializer(function() { | |
// Put loading view under App main region | |
var loadingView = new module.LoadingView(); | |
App.mainRegion.show(loadingView); | |
// Get weather | |
var weatherModel = new module.WeatherModel({ | |
query : "SP/Sevilla" | |
}); | |
var weatherView = new module.WeatherView({ | |
model : weatherModel | |
}); | |
// How can I test this on my spec? | |
weatherModel.fetch(); | |
}); | |
return module; | |
} | |
); |
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
define( | |
["modules/index/index"], | |
function(Index) { | |
describe("Index module", function() { | |
it("Should fetch WeatherModel on start", function() { | |
// With this two spies I assert that "new WeatherModel" and "new WeatherView" are called at start of IndexModule | |
var spyWeatherModel = sinon.spy(Index, "WeatherModel"); | |
var spyWeatherView = sinon.spy(Index, "WeatherView"); | |
// How do I assert that "weatherModel.fetch();" has been called on "Index.start()"? I can't spy on "fetch" because: "Attempted to wrap undefined property fetch as function" | |
var spyWeatherModelFetch = sinon.spy(Index.WeatherModel, "fetch"); | |
Index.start(); | |
expect(spyWeatherModel).toHaveBeenCalled(); | |
expect(spyWeatherView).toHaveBeenCalled(); | |
expect(spyWeatherModelFetch).toHaveBeenCalled(); | |
}); | |
}); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment