Skip to content

Question about mocking axios: What if i also want to return error from async call? #16

Open
@dmngu9

Description

@dmngu9

So for your mock, axios return a promise with value which is a happy path. However, what if i want to mock it to return an error.

Wonder if i can do like this

const func = jest.fn();
jest.mock('axios', () => {
    get: func
});

then in each test case, can i do func.mockReturnValue for happy and error case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions