
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
interface-mock
Advanced tools
C#-like API for creating mock in TypeScript for Node.js environment
npm install --save-dev interface-mock
or
yarn add --dev interface-mock
Create mock by passing interface to it and providing default implementation, then call .verify() method to check whether the method was called. Additionally you can specify how many times it should have been called
import { createInterfaceMock } from 'interface-mock';
interface IBus {
send: (message: string) => Promise<void>;
}
describe('SomeTest', () => {
it('works', () => {
const busMock = createInterfaceMock<IBus>({ send: async () => {} });
const someService = new SomeService(busMock);
someService.execute();
busMock.verify(m => m.send('Hello'));
});
it('works 2', () => {
const busMock = createInterfaceMock<IBus>({ send: async () => {} });
const someService = new SomeService(busMock);
someService.execute();
busMock.verify(m => m.send('Hello'), { times: 2 });
});
});
Additionally you can manually specify the resulting type of createInterfaceMock function:
import { createInterfaceMock, InterfaceMock } from 'interface-mock';
interface IBus {
send: (message: string) => Promise<void>;
}
describe('SomeTest', () => {
let busMock: InterfaceMock<IBus>;
beforeEach(() => {
busMock = createInterfaceMock<IBus>({ send: async () => {} });
});
it('works', () => {
const someService = new SomeService(busMock);
someService.execute();
busMock.verify(m => m.send('Hello'));
});
});
FAQs
C#-like API for creating mock in TypeScript (Node.js)
The npm package interface-mock receives a total of 1 weekly downloads. As such, interface-mock popularity was classified as not popular.
We found that interface-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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.