首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何在Sinon中用Typescript/Angular检查http calledWith

在Sinon中使用Typescript/Angular检查http calledWith的方法如下:

  1. 首先,确保你已经安装了Sinon和Typescript/Angular相关的依赖。
  2. 在你的测试文件中,导入所需的依赖:
代码语言:txt
复制
import { SinonSpy, SinonStub, SinonFakeXMLHttpRequest } from 'sinon';
import { HttpClient } from '@angular/common/http';
  1. 创建一个Sinon的spy或stub来替代HttpClient中的http请求:
代码语言:txt
复制
const httpClientSpy: SinonSpy = sinon.createSpyObj('HttpClient', ['get']);

或者

代码语言:txt
复制
const httpClientStub: SinonStub = sinon.stub(HttpClient.prototype, 'get');
  1. 在测试用例中,使用Sinon的calledWith方法来检查http请求是否被正确调用:
代码语言:txt
复制
expect(httpClientSpy.get.calledWith('your-url')).toBeTruthy();

或者

代码语言:txt
复制
expect(httpClientStub.calledWith('your-url')).toBeTruthy();

这样,你就可以在Sinon中使用Typescript/Angular来检查http calledWith了。

对于Sinon的更多用法和详细信息,你可以参考腾讯云的产品文档: 腾讯云Sinon产品介绍

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的视频

领券