Our team is in the process of transitioning to TypeScript, but we want to continue using Sinon for our tests.
In the past, we used JavaScript Service Unit Tests like this:
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;
});
The service.get()
method triggers an HTTP call to ApiService/GetMethod
, and we verify that it is called with the correct URL.
How can we achieve the same functionality in TypeScript with Sinon?
Currently, this is what we are attempting:
it('should get list', () => {
// Arrange
let apiServiceStub: SinonStubbedInstance<ApiService>;
// Act
apiServiceStub= sinon.createStubInstance(ApiService);
let result = apiServiceStub.get();
// Assert -- Here is my question: how can I replicate this line, as it doesn't work currently
applicationServiceStub.**calledWith**(`${constants.APPLICATION_BASE}ApiService/GetMethod`).should.be.true;
});
As it stands, the calledWith method only checks against the passed arguments of the method and not how the HTTP call is made. I need a solution that can emulate the behavior seen in the first example - creating an HTTP stub.