ts-sinon
ts-sinon copied to clipboard
stubObject on got library crashes
Cannot stub got (the http request library)
` import sinon, { stubObject } from "ts-sinon"; import got, { Got } from 'got';
const gotMock = stubObject<Got>(got); //crashes `
Error message: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
I get this also trying to mock AxiosInstant like so
const axiosInstance = axios.create();
const mockAxios = stubObject<AxiosInstance>(axiosInstance);
I get this also trying to mock AxiosInstant like so
const axiosInstance = axios.create(); const mockAxios = stubObject<AxiosInstance>(axiosInstance);
@sblausten you can mock AxiosInstance
this way:
//import
import { stubInterface } from "ts-sinon";
//...
const expectedResponse = { "status": 200 };
const stub = stubInterface<AxiosInstance>();
stub.post.withArgs(
`/v1/my-apy`,
{
data: {
foo: 'bar'
}
},
)
.resolves(Promise.resolve(expectedResponse));
//assertion
expect(stub.post.called).to.be.true;