mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-26 16:21:55 +08:00
update nav-controller tests to angular test methods
This commit is contained in:
@ -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, {}, {});
|
||||
});
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user