typescript Ejemplo测试异步
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript Ejemplo测试异步相关的知识,希望对你有一定的参考价值。
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
import { CardComponent } from './card.component';
import {of} from 'rxjs';
import {CardModel} from '../../../models/card.model';
import {CardService} from '../../../services/card.service';
describe('CardComponent', () => {
let component: CardComponent;
let fixture: ComponentFixture<CardComponent>;
let mockCardService;
const CARD: CardModel = {
id: 1,
front: 'front',
back: 'back',
themeId: 1
};
beforeEach(async(() => {
mockCardService = jasmine.createSpyObj(['getCard']);
mockCardService.getCard.and.returnValue(CARD);
TestBed.configureTestingModule({
declarations: [ CardComponent ],
providers: [
{ provide: CardService, useValue: mockCardService }
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should populate "card" attribute when initialized', (done) => {
setTimeout(() => {
expect(component.card).toEqual(CARD);
done();
}, 100);
});
});
以上是关于typescript Ejemplo测试异步的主要内容,如果未能解决你的问题,请参考以下文章
typescript Ejemplo de test para服务
使用 axios、TypeScript 模板和异步函数对 VueJS 进行单元测试
TypeScript之异步函数
带有 Typescript 错误的玩笑:超时 - 在 jest.setTimeout.Timeout 指定的 5000 毫秒超时内未调用异步回调
text ejemplo de vue
markdown Ejemplo documento Cacher