Skip to content

can you mock functions from a module? #223

@sunnz

Description

@sunnz

looking to mock a function (foo) imported from a module (../foo), for example when using jest:

jest.mock('../foo'); // this happens automatically with automocking
const foo = require('../foo');

// foo is a mock function
foo.mockImplementation(() => 42);
foo();
// > 42

see https://jestjs.io/docs/mock-functions#mock-implementations

I am doing this for an existing codebase that uses ts-mockito, so don't want to throw jest into the mix. :)

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