【发布时间】:2021-05-06 19:24:54
【问题描述】:
我们如何模拟订阅方法消耗的内容..我能够初始化 testService 但努力模拟订阅的内容
export class AppComponent {
constructor(){}
CheckTestLink(link: any) {
this.testService.init().subscribe( configUsers => {
const conf: [] = configUsers['entries'].filter( entry =>
(this.userName === entry.content.properties.user_name );
if (conf.length > 0) {
} else {
}
},
errors => {
this.ErrorService.notifyError('Error fetching details.');
});
}
}
应用组件
describe( 'AppComponent', () => {
let fixture: AppComponent;
let TestServiceMOck;
beforeEach( () => {
TestServiceMOck={
init:jest.fn().mockImplementation(subscribe=>{return of('test')})
}
fixture = new AppComponent(
);
});
【问题讨论】:
标签: angular unit-testing testing jestjs