-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathrouter.spec.js
More file actions
72 lines (58 loc) · 2.18 KB
/
router.spec.js
File metadata and controls
72 lines (58 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// **Note**: These tests are for the Chapter 5 "abbreviated" router
// that omits most of the real `App.Routers.Router` implementation
// and keeps just the routing logic.
//
// To review the spec for the *real* Notes router, see:
// "notes/test/js/spec/routers/router.spec.js"
describe("App.Routers.Router", function () {
// Default option: Trigger and replace history.
var opts = { trigger: true, replace: true };
beforeEach(function () {
// Stub route methods.
sinon.stub(App.Routers.Router.prototype, "note");
sinon.stub(App.Routers.Router.prototype, "notes");
// Create router with stubs and manual fakes.
this.router = new App.Routers.Router();
// Start history to enable routes to fire.
Backbone.history.start();
// Spy on all route events.
this.routerSpy = sinon.spy();
this.router.on("route", this.routerSpy);
});
afterEach(function () {
Backbone.history.stop();
App.Routers.Router.prototype.note.restore();
App.Routers.Router.prototype.notes.restore();
});
it("can route to note", function () {
this.router.navigate("note/1/edit", opts);
// Check router method.
expect(App.Routers.Router.prototype.note)
.to.have.been.calledOnce.and
// Updated for Backbone.js v1.1.2. Was:
// .to.have.been.calledWithExactly("1", "edit");
.to.have.been.calledWithExactly("1", "edit", null);
// Check route event.
expect(this.routerSpy)
.to.have.been.calledOnce.and
// Updated for Backbone.js v1.1.2. Was:
// .to.have.been.calledWith("note", ["1", "edit"]);
.to.have.been.calledWith("note", ["1", "edit", null]);
});
it("can route around", function () {
// Bounce between routes.
this.router.navigate("", opts);
this.router.navigate("note/1/edit", opts);
this.router.navigate("", opts);
// Check router method.
expect(App.Routers.Router.prototype.notes)
.to.have.been.calledTwice.and
// Updated for Backbone.js v1.1.2. Was:
// .to.have.been.calledWithExactly();
.to.have.been.calledWithExactly(null);
// Check route event.
expect(this.routerSpy)
.to.have.been.calledThrice.and
.to.have.been.calledWith("notes");
});
});