如何为单元测试用例按角度模拟this.getResults $ .subscribe的数据?

时间:2020-04-03 01:52:54

标签: angular unit-testing jasmine ngrx-store

displayMesssage(){
this.getResults$.subscribe(data =>{
if(data !== undefined && data !== null){
 this.message = data.message;
}else{
 this.message="Empty";
});
}

如何在茉莉花中为上述用例模拟数据?

2 个答案:

答案 0 :(得分:1)

类似的事情,可能会起作用。如果这不起作用,我需要查看完整的规格和完整的组件。

Private Sub Worksheet_Change(ByVal Target As Range)
Dim shp As Shape
If Intersect(Target, [B:B]) Is Nothing Then Exit Sub
If Target.Row Mod 20 = 0 Then Exit Sub
On Error GoTo son

For Each shp In ActiveSheet.Shapes
If shp.Type = msoPicture And shp.TopLeftCell.Address = Target.Offset(0, 4).Address Then shp.Delete
Next

If Target.Value <> "" And Dir(ThisWorkbook.Path & "\" & Target.Value & ".jpg") = "" Then
        'picture not there!
        MsgBox Target.Value & " Doesn't exist!"
End If

ActiveSheet.Pictures.Insert(ThisWorkbook.Path & "\" & Target.Value & ".jpg").Select
Selection.Top = Target.Offset(0, 5).Top
Selection.Left = Target.Offset(0, 5).Left

With Selection.ShapeRange
.LockAspectRatio = msoFalse
.Height = Target.Offset(0, 5).Height
.Width = Target.Offset(0, 5).Width
End With
Target.Offset(1, 0).Select
son:

End Sub

答案 1 :(得分:0)

尝试这种方式

return new Promise((resolve, reject) => {
  setTimeout(() => {
    const data = { res: "put your data here" };
    resolve(data);
  }, 2000);
});

Stackblitz example和模拟服务