Skip to content

Instantly share code, notes, and snippets.

@kazu69
Created May 22, 2012 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazu69/2768291 to your computer and use it in GitHub Desktop.
Save kazu69/2768291 to your computer and use it in GitHub Desktop.
Backbone + sinonjsでのbackbone Routerのテスト例
describe("Routerは", function() {
beforeEach(function() {
this.router = App.Router();
// routes {
// '' : 'index',
// 'login' : 'login'
// }
this.routeSpy = sinon.spy();
try {
Backbone.history.start({silent:true, pushState:true});
} catch(e) {
}
this.router.navigate("tests/SpecRunner.html");
});
afterEach(function(){
this.router.navigate("tests/SpecRunner.html");
});
it('正しい数のroutesをもつ', function() {
expect(_.size(this.router.routes)).toEqual(2);
});
it('/ で正しいメソッドが呼ばれる', function () {
expect(this.router.routes['']).toEqual('index');
});
it("/に遷移できる", function() {
this.router.bind("route:index", this.routeSpy);
this.router.navigate("", true);
expect(this.routeSpy.calledOnce).toBeTruthy(); // -> true
expect(this.routeSpy.calledWith()).toBeTruthy(); // -> true
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment