Created
May 22, 2012 10:49
-
-
Save kazu69/2768291 to your computer and use it in GitHub Desktop.
Backbone + sinonjsでのbackbone Routerのテスト例
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("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