Angular 在ionic2中设置TDD

Angular 在ionic2中设置TDD,angular,ionic2,testbed,Angular,Ionic2,Testbed,我遵循了Joshua Moroney关于Ionic2和TDD的教程,但在尝试调试错误时遇到了问题 核心示例如下: import { TestBed, ComponentFixture, async } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { DebugElement } from '@angular/core'; import { IonicModule, Nav

我遵循了Joshua Moroney关于Ionic2和TDD的教程,但在尝试调试错误时遇到了问题

核心示例如下:

import { TestBed, ComponentFixture, async } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { IonicModule, NavController } from 'ionic-angular';
import { MyApp } from '../../app/app.component';
import { TabsPage } from './tabs';

let comp: TabsPage;
let fixture: ComponentFixture<TabsPage>;
let de: DebugElement;
let el: HTMLElement;

describe('Page: Tabs Page', () => {

beforeEach(async(() => {

    TestBed.configureTestingModule({

        declarations: [MyApp, TabsPage],

        providers: [
            NavController
        ],

        imports: [
            IonicModule.forRoot(MyApp)
        ]

    }).compileComponents();

}));

beforeEach(() => {
    fixture = TestBed.createComponent(TabsPage);
    comp    = fixture.componentInstance;

});

afterEach(() => {
    fixture.destroy();
    comp = null;
    de = null;
    el = null;
});

it('is created', () => {
    expect(fixture).toBeTruthy();
    expect(comp).toBeTruthy();

});

});
有人能给我指一个关于如何解决这些问题的教程吗;不只是为这个问题提供解决方案

谢谢


安迪

我遇到了同样的问题。根据爱奥尼亚文档,“每个单独的爱奥尼亚标签都是一个NavController的声明性组件”。因此,您需要为NavController使用提供程序,然后使用模拟类作为类。在这里,您需要定义一个注册函数和一个注销ChildNav组件的函数。另见: 我将Josh Morony提供的基类用作一个类,并将其扩展为包括:

public registerChildNav(nav: any) {
  // do nothing
}

public unregisterChildNav(nav: any) {
  // do nothing
}
tabs spec页面有以下相关条目(我将我的mock放在与src dir相同级别的test mocks dir中):

应该这样做

import { Component } from '@angular/core';

@Component({
  templateUrl: 'tabs.html'
})

export class TabsPage {

  constructor() {

  }
}
public registerChildNav(nav: any) {
  // do nothing
}

public unregisterChildNav(nav: any) {
  // do nothing
}
import { NavController } from 'ionic-angular';
import { NavMock } from '../../../test-mocks/mocks';


providers: [
  //NavController,
  {
    provide: NavController,
    useClass: NavMock
  },
]