
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
jest-mock-exports
Advanced tools
Simplifies mocking exports for Jest.
import { libFn } from 'some-library';
import { doStuff, logicFn, someConfig } from './my/file';
import { whatAreWeTesting } from './file';
import { mockExportedFn, mockExportedObject, spyOnExportedFn } from 'jest-mock-exports';
// mocks with jest.fn() by default:
const mocked1 = mockExportedFn(libFn)
// provide implementation:
const mocked2 = mockExportedFn(doStuff, () => 'mock implementation')
// mocking objects:
mockExportedObject(someConfig, { new: 'value' })
// spying on functions without changing their implementation:
const spy = spyOnExportedFn(logicFn)
it('works', async () => {
mocked2.mockResolvedValueOnce('return for this test')
await whatAreWeTesting()
expect(mocked1).toHaveBeenCalledTimes(1)
expect(mocked2).toHaveBeenCalledWith('params')
expect(spy).toHaveBeenCalledWith('params')
})
For convenience, you can group the mocks:
const mocks = {
fn1: mockExportedFn(fn1),
fn2: mockExportedFn(fn1, () => 'mock implementation'),
obj: mockExportedObject(obj, { new: 'value' }),
}
it('works', async () => {
mocks.fn1.mockResolvedValueOnce('return for this test')
await whatAreWeTesting()
expect(mocks.fn2).toHaveBeenCalledWith('params')
})
npm i -D jest-mock-exports
Add to jest.config.ts
(or .js
) in the root:
import type { Config } from "jest";
const config: Config = {
runtime: 'jest-mock-exports/jest.runtime',
};
export default config;
FAQs
Easy mocking of exported functions and objects in Jest
The npm package jest-mock-exports receives a total of 1 weekly downloads. As such, jest-mock-exports popularity was classified as not popular.
We found that jest-mock-exports demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.