Rules
Every rule from ESLint, Oxlint and Biome. Pick a rule to see its example. Reach is the weekly npm downloads of the presets that enable a rule; trend is its change over the last quarter.
Every rule from ESLint, Oxlint and Biome. Pick a rule to see its example. Reach is the weekly npm downloads of the presets that enable a rule; trend is its change over the last quarter.
jest.mock('../moduleName', () => {
return jest.fn(() => 42);
});
jest.mock('./module', () => ({
...jest.requireActual('./module'),
foo: jest.fn(),
}));
jest.mock('random-num', () => {
return jest.fn(() => 42);
});// Uses typeof import()
jest.mock<typeof import('../moduleName')>('../moduleName', () => {
return jest.fn(() => 42);
});
jest.mock<typeof import('./module')>('./module', () => ({
...jest.requireActual('./module'),
foo: jest.fn(),
}));
// Uses custom type
jest.mock<() => number>('random-num', () => {
return jest.fn(() => 42);
});
// No factory
jest.mock('random-num');
// Virtual mock
jest.mock(
'../moduleName',
() => {
return jest.fn(() => 42);
},
{ virtual: true },
);Popular · 1 of 50
Disallow using jest.mock() factories without an explicit type parameter
jest.mock('../moduleName', () => {
return jest.fn(() => 42);
});
jest.mock('./module', () => ({
...jest.requireActual('./module'),
foo: jest.fn(),
}));
jest.mock('random-num', () => {
return jest.fn(() => 42);
});// Uses typeof import()
jest.mock<typeof import('../moduleName')>('../moduleName', () => {
return jest.fn(() => 42);
});
jest.mock<typeof import('./module')>('./module', () => ({
...jest.requireActual('./module'),
foo: jest.fn(),
}));
// Uses custom type
jest.mock<() => number>('random-num', () => {
return jest.fn(() => 42);
});
// No factory
jest.mock('random-num');
// Virtual mock
jest.mock(
'../moduleName',
() => {
return jest.fn(() => 42);
},
{ virtual: true },
);