具有延迟加载的 Ionic 页面单元测试的工作示例

Working Example of an Unit Test of a Ionic Page with lazy load

一段时间以来,我一直在尝试重写我的 'broken' 单元测试,因为使用 IonicPageModule 延迟加载,但没有任何运气。

非常感谢任何人提供一些指导或工作示例。

如果不存在工作示例(我对此表示怀疑),我将根据在此页面上收集的反馈帮助创建一个。

欢迎任何帮助。

感谢RomainFallet I've found (and recreated) a working ionic 3 Unit Test with lazy loading on his github的帮助(见2.7),为了方便,我也分享到这里

 /* Import Ionic & Angular core elements */
import { async, TestBed } from '@angular/core/testing';
import { IonicModule } from 'ionic-angular';

/* Import modules */
import { HomePageModule } from './home.module';

/* Import components */
import { AppComponent } from '../../app/app.component';

/* Import pages */
import { HomePage } from './home';

describe('HomePage', () => {
    let fixture;
    let component;

    beforeEach(async(() => {
        TestBed.configureTestingModule({
            declarations: [],
            imports: [
                IonicModule.forRoot(AppComponent),
                HomePageModule
            ],
            providers: [
            ]
        })
    }));

    beforeEach(() => {
        fixture = TestBed.createComponent(HomePage);
        component = fixture.componentInstance;
    });

    it ('should create a valid instance of HomePage', () => {
        expect(component instanceof HomePage).toBe(true);
    });
});

希望它也能帮助其他人找到自己的路。