Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何在ionic2中使用karma/Jasmine测试异步函数?_Angular_Ionic2_Jasmine_Angular2 Testing - Fatal编程技术网

Angular 如何在ionic2中使用karma/Jasmine测试异步函数?

Angular 如何在ionic2中使用karma/Jasmine测试异步函数?,angular,ionic2,jasmine,angular2-testing,Angular,Ionic2,Jasmine,Angular2 Testing,下面我写了一段代码,其中有一个异步函数,在内部使用setTimeout()并在3秒钟后打印消息 我得用茉莉花来写说明书 我已经遵循了,但是我不知道如何在代码中应用它 home.ts //implementing only function written in a class.All imports are done properly. click(){ function delayedAlert(message: string, time: number, cb) { retu

下面我写了一段代码,其中有一个异步函数,在内部使用setTimeout()并在3秒钟后打印消息

我得用茉莉花来写说明书

我已经遵循了,但是我不知道如何在代码中应用它

home.ts

//implementing only function written in a class.All imports are done properly.

click(){

function delayedAlert(message: string, time: number, cb) {
      return setTimeout(() => cb(message), time);
    }
    delayedAlert('Aditya3', 3000, (message) => console.log(message));//function is called
  }
}
describe('Asynchronous call', () => {
    let fixture: ComponentFixture<HomePage>;
    let comp: HomePage;
    let de: DebugElement;
    let el: HTMLElement;


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

    beforeEach(() => {
        fixture = TestBed.createComponent(HomePage);
        comp = fixture.componentInstance;
        de = fixture.debugElement

    });

it('Asynchronous testing with callback', ()=>{
         //how to write the spec here for the asynchronous function wrriten in the above class using Karma/Jasmine.
})
});
home.spec.ts

//implementing only function written in a class.All imports are done properly.

click(){

function delayedAlert(message: string, time: number, cb) {
      return setTimeout(() => cb(message), time);
    }
    delayedAlert('Aditya3', 3000, (message) => console.log(message));//function is called
  }
}
describe('Asynchronous call', () => {
    let fixture: ComponentFixture<HomePage>;
    let comp: HomePage;
    let de: DebugElement;
    let el: HTMLElement;


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

    beforeEach(() => {
        fixture = TestBed.createComponent(HomePage);
        comp = fixture.componentInstance;
        de = fixture.debugElement

    });

it('Asynchronous testing with callback', ()=>{
         //how to write the spec here for the asynchronous function wrriten in the above class using Karma/Jasmine.
})
});
description('异步调用',()=>{
let夹具:组件夹具;
让comp:主页;
设de:DebugElement;
让el:HTMLElement;
beforeach(异步(()=>{
TestBed.configureTestingModule({
声明:[主页],
进口:[
IonicModule.forRoot(主页),
],
提供者:[NavController],
}).compileComponents();
}));
在每个之前(()=>{
fixture=TestBed.createComponent(主页);
comp=夹具。组件状态;
de=fixture.debugElement
});
它('使用回调进行异步测试',()=>{
//如何在这里使用Karma/Jasmine为上述类中的异步函数writen编写规范。
})
});
在测试规范中标记的注释中,我需要编写规范。

使用done()方法。看看这个


在这篇文章中,jasmine.async lib使用了async.it等,你能帮助我在不使用jasmine.async lib的情况下编写这个规范吗?我无法实现它。你能帮我吗?