Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stubObject on got library crashes #215

Open
chanep opened this issue May 27, 2021 · 2 comments
Open

stubObject on got library crashes #215

chanep opened this issue May 27, 2021 · 2 comments

Comments

@chanep
Copy link

chanep commented May 27, 2021

Cannot stub got (the http request library)

`
import sinon, { stubObject } from "ts-sinon";
import got, { Got } from 'got';

const gotMock = stubObject(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

@sblausten
Copy link

I get this also trying to mock AxiosInstant like so

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

@ricardomouraspl
Copy link

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants