ts-sinon icon indicating copy to clipboard operation
ts-sinon copied to clipboard

stubObject on got library crashes

Open chanep opened this issue 3 years ago • 2 comments

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

chanep avatar May 27 '21 14:05 chanep

I get this also trying to mock AxiosInstant like so

const axiosInstance = axios.create();
const mockAxios = stubObject<AxiosInstance>(axiosInstance);

sblausten avatar Dec 23 '21 13:12 sblausten

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;

ricardomouraspl avatar May 05 '22 19:05 ricardomouraspl