Here is the complete test using Jasmine and Sinon :
code:
describe("Given the Router", function(){ var router = null; beforeEach(function(){ router = Router.create(); }); afterEach(function(){ router = null; }); it("Should be defined", function(){ expect(router).toBeDefined(); }); it("Should have an root route", function(){ expect(router.get("root")).toBeDefined(); }); describe("its root route", function(){ var root = null; beforeEach(function(){ root = router.get("root").create(); }); afterEach(function(){ root = null; }); it("should have an index route", function(){ expect(root.get("index")).toBeDefined(); }); describe("its index route", function(){ var indexRoute = null; beforeEach(function(){ indexRoute = root.get("index").create(); }); it ("should have route of /", function(){ expect(indexRoute.get("route")).toEqual("/"); }); it ("should connect the outlets to home", function(){ var fakeRouter = Em.Object.create({applicationController: {connectOutlet: function(){} } }); var connectOutletSpy = sinon.spy(fakeRouter.applicationController, "connectOutlet"); var methodCall = connectOutletSpy.withArgs({name:"home"}); indexRoute.connectOutlets(fakeRouter); expect(methodCall.calledOnce).toBeTruthy(); }); }); }); });
Hope this helps.
source share