log*_*ger 9 typescript jestjs nestjs
jest
.spyOn(webService.prototype, 'isEnabled')
.mockImplementation(() => {
return Promise.resolve(true)
})
jest
.spyOn(webService.prototype, 'isEnabled')
.mockImplementation(() => {
return Promise.resolve(false)
})
Run Code Online (Sandbox Code Playgroud)
所以我想要的是如果参数中有“YES”字符串,则返回“true”。如果参数中有“NO”,则返回“false”。
函数的打字稿如下所示。
public isEnabled(featureId: string): Promise<boolean> {
return this.toggle.isEnabled(featureId)
}
Run Code Online (Sandbox Code Playgroud)
Jay*_*iel 20
jonrsharpe 在评论中的想法是正确的。您可以向您的间谍添加模拟实现并执行类似的操作
jest.spyOn(webService.prototype, 'isEnabled')
.mockImplementation((yesOrNo: string) => {
if (yesOrNo.includes('YES')) {
return true;
} else {
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
现在它适用于YES和NO参数。当然,您可以根据您的需要添加和定制逻辑。
| 归档时间: |
|
| 查看次数: |
23875 次 |
| 最近记录: |