From a1155b4663b13be238b2aa6ab9e5e16102747194 Mon Sep 17 00:00:00 2001 From: Tim Lancina Date: Thu, 8 Oct 2015 12:29:41 -0500 Subject: [PATCH] update nav-controller tests to angular test methods --- .../nav/test/nav-controller.spec.ts | 82 ++++++++++++++----- ionic/components/nav/view-controller.ts | 2 +- 2 files changed, 62 insertions(+), 22 deletions(-) diff --git a/ionic/components/nav/test/nav-controller.spec.ts b/ionic/components/nav/test/nav-controller.spec.ts index 2a41a025ae..70c965074e 100644 --- a/ionic/components/nav/test/nav-controller.spec.ts +++ b/ionic/components/nav/test/nav-controller.spec.ts @@ -1,42 +1,76 @@ +import { + ddescribe, + describe, + xdescribe, + it, + iit, + xit, + expect, + beforeEach, + afterEach, + AsyncTestCompleter, + inject, + beforeEachBindings +} from 'angular2/test'; + +import {Compiler} from 'angular2/angular2'; + import { NavController, IonicConfig, + Page, ViewController } from 'ionic/ionic'; + +@Page({ + template: '' +}) +class SomePage {} + export function run() { - describe("NavController", function(){ - beforeEach( function(){ - this.nav = new NavController(null, null, new IonicConfig(), null, null, null, null, null); + describe("NavController", () => { + let nav; + + beforeEach(inject([Compiler], compiler => { + nav = new NavController(null, null, new IonicConfig(), null, compiler, null, null, null); + })); + + it('should exist', () => { + expect(nav).not.toBeUndefined(); }); - it('should exist', function(){ - expect(this.nav).not.toBeUndefined(); - }); - - describe("getActive", function(){ - it('should return null if there is no active view', function(){ - var active = this.nav.getActive(); + describe("getActive", () => { + it('should return null if there is no active view', () => { + var active = nav.getActive(); expect(active).toBe(null); }); - it('should return the first active page', function(){ + it('should return the first active page', () => { let activeView = new ViewController(); activeView.state = 1; // ACTIVE_STATE - this.nav.add(activeView); - var active = this.nav.getActive(); + nav.add(activeView); + var active = nav.getActive(); + + expect(active).toBe(activeView); + + let secondActiveView = new ViewController(); + secondActiveView.state = 1; // ACTIVE_STATE + + nav.add(secondActiveView); + active = nav.getActive(); expect(active).toBe(activeView); }); }); - describe("push", function(){ - it('should return a rejected Promise if componentType is falsy', function(done){ + describe("push", () => { + it('should return a rejected Promise if componentType is falsy', done => { let s = jasmine.createSpy('success'); let f = jasmine.createSpy('fail'); - let promise = this.nav.push(undefined, {}, {}); + let promise = nav.push(undefined, {}, {}); promise.then(s, f).then(() => { expect(s).not.toHaveBeenCalled(); @@ -45,20 +79,26 @@ export function run() { }); }); - it('should throw an error if componentType truthy, but is not a function', function(){ - let push = () => this.nav.push({}, {}, {}); + it('should throw an error if componentType truthy, but is not a function', () => { + let push = () => nav.push({}, {}, {}); expect(push).toThrow(); - push = () => this.nav.push("string", {}, {}); + push = () => nav.push("string", {}, {}); expect(push).toThrow(); - push = () => this.nav.push(42, {}, {}); + push = () => nav.push(42, {}, {}); expect(push).toThrow(); - push = () => this.nav.push(true, {}, {}); + push = () => nav.push(true, {}, {}); expect(push).toThrow(); }); + it('be successful', () => { + expect(SomePage).toBeDefined(); + + nav.push(SomePage, {}, {}); + }); + }) }); diff --git a/ionic/components/nav/view-controller.ts b/ionic/components/nav/view-controller.ts index 7169e22e39..38707e2bc6 100644 --- a/ionic/components/nav/view-controller.ts +++ b/ionic/components/nav/view-controller.ts @@ -36,7 +36,7 @@ export class ViewController { return done(); } - // compile the componenet and create a ProtoViewRef + // compile the component and create a ProtoViewRef navCtrl.compileView(this.componentType).then(hostProtoViewRef => { // get the pane the NavController wants to use