
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@node-loaders/jest-mock
Advanced tools
Integrates [@node-loaders/mock](https://github.com/node-loaders/loaders/tree/main/workspaces/mock#node-loadersmock) with jest-mock using a jest like api.
Integrates @node-loaders/mock with jest-mock using a jest like api.
For configuration tools, refer to usage
@node-loaders/jest-mock
re-exports @node-loaders/mock
default loader, for non default loader use @node-loaders/mock
directly.
Import a module with mocked dependencies:
import { mock, checkMocks, restoreMocks } from '@node-loaders/jest-mock';
const mockedPath = (await mock) < typeof import('path') > 'path';
const mockedModule = await import('./module.js');
describe(() => {
after(() => {
checkMocks(); // Detects for unused mocks to avoid mistakes on import changes.
restoreMocks(); // Restore jest-mocks to initial state.
});
it(async () => {
mockedModule.run();
expect(mockedPath.join).toBeCalled();
});
});
Due to technical limitation, mock
+ import
only works for second level imported modules, which is equivalent to importMock
with { [maxDepth]: 1 }
options.
For advanced options use importMock
instead of import
.
For more information on about importMock
refer to mock.
import { mock, importMock, checkMocks, fn, restoreMocks, maxDepth, ignoreUnused, fullMock } from '@node-loaders/jest-mock';
const mockedPath = (await mock) < typeof import('path') > 'path';
const mockedFunction = fn.mock();
const mockedModule = await importMock('./module.js', {
[maxDepth]: number, // -1 by default
[ignoreUnused]: boolean, // false by default
'../a-mocked-module.js': {
[fullMock]: boolean, // false by default
func: mockedFunction,
},
});
describe(() => {
after(() => {
checkMocks(); // Detects for unused mocks to avoid mistakes on import changes.
restoreMocks(); // Restore jest-mocks to initial state.
});
it(async () => {
mockedModule.run();
expect(mockedPath.join).toBeCalled();
expect(mockedFunction).toBeCalled();
});
});
MIT
FAQs
Integrates [@node-loaders/mock](https://github.com/node-loaders/loaders/tree/main/workspaces/mock#node-loadersmock) with jest-mock using a jest like api.
We found that @node-loaders/jest-mock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.