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

问题描述 投票:0回答:1
我们正在迁移到TypeScript,我们希望继续使用Sinon进行测试。

在使用这样的JavaScript服务单元测试之前:

it('should get buyer application status count', function () { let httpStub = sandbox.stub(http, 'get').returns({ then: function () { return []; } }); let result = service.get(); httpStub.calledWith(`${constants.APPLICATION_BASE}ApiService/GetMethod`).should.be.true; });

service.get()方法对http进行ApiService/GetMethod调用,我们确保使用此确切的URL对其进行调用。

我们如何使用Sinon在TypeScript中实现相同?

目前,我们这样做:

it('should get list', () => { // Arrange let apiServiceStub: SinonStubbedInstance<ApiService>; // Act apiServiceStub= sinon.createStubInstance(ApiService); let result = apiServiceStub.get(); // Assert -- Here is my question, how to do this line, it doesn't work now applicationServiceStub.**calledWith**(`${constants.APPLICATION_BASE}ApiService/GetMethod`).should.be.true; });

现在已完成,被调用的方法仅将传递的参数与方法匹配,而不匹配如何调用HTTP调用。我需要可以创建类似于第一个示例的内容-http存根。

我们正在迁移到TypeScript,我们希望继续使用Sinon进行测试。在我们像这样使用JavaScript服务单元测试之前:it('应该获取买方应用程序状态计数',函数(){...

angular typescript unit-testing mocha sinon
1个回答
0
投票
乐于分享解决方案:
© www.soinside.com 2019 - 2024. All rights reserved.