嘲笑茉莉花中的蜘蛛对象
我的组件订阅了类似服务的可观察到的服务:
ngOnInit(): void {
this.sub.add(
this.notesService.notes$.subscribe(notes => {
this.notes = notes.map(note => {
let profilePicture = generateProfilePicture(note.creator)
return {
...note,
color: profilePicture.color,
initials: profilePicture.initials
}
})
})
);
}
在我的单元测试中,我为笔记服务创建了一个spyobject。我该如何存根note $可观察?
providers: [
ConfirmationService,
{
provide: HttpClient,
useValue: jasmine.createSpyObj("HttpClient", ["get", "post", "put", "delete"])
},
{
provide: NotesService,
useValue: jasmine.createSpyObj("NotesService",
["addNote", "getNotesByRefId", "editNote", "deleteNote"])
}
]
My component subscribes to an observable of a service like that:
ngOnInit(): void {
this.sub.add(
this.notesService.notes$.subscribe(notes => {
this.notes = notes.map(note => {
let profilePicture = generateProfilePicture(note.creator)
return {
...note,
color: profilePicture.color,
initials: profilePicture.initials
}
})
})
);
}
In my unit test I created a spyobject for the NoteService. How can I stub the note$ observable?
providers: [
ConfirmationService,
{
provide: HttpClient,
useValue: jasmine.createSpyObj("HttpClient", ["get", "post", "put", "delete"])
},
{
provide: NotesService,
useValue: jasmine.createSpyObj("NotesService",
["addNote", "getNotesByRefId", "editNote", "deleteNote"])
}
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
分机分开(需要在需要时使用):
Typings apart (use
as any
when needed) :