0

I have some runtime importable module imports via AMD define. Everything is working as expected but I just cannot mock any runtime module inside the tests.

Error message without mocks: Cannot find module 'MyModule' from ... I also get the same error message when I try to jest.mock the module. just the error happens inside the test file then.

// globals.d.ts
declare module 'config' {
    const val: IConfig;
    export default val;
}
// main.ts
/// <reference path="./globals.d.ts" />
import config from 'config';
[...]
// main.spec.ts
import { main } from "./main.ts"
[...]

1 Answer 1

3

A module that is mocked with jest.mock is expected to exist. Non-existent mocked modules should be labeled as virtual:

jest.mock('MyModule', () => ..., {virtual: true});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.