
Product
Introducing Reports: An Extensible Reporting Framework for Socket Data
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.
@golevelup/ts-sinon
Advanced tools
Utilities for making testing [NestJS](https://docs.nestjs.com) applications easier.
Utilities for making testing NestJS applications easier.
::: code-group
npm install @golevelup/ts-sinon -D
yarn add @golevelup/ts-sinon -D
pnpm add @golevelup/ts-sinon -D
:::
createMock function into your test class.createMock function with its generic type input.Here's an example with NestJS' ExecutionContext:
import { createMock } from '@golevelup/ts-sinon';
import { ExecutionContext } from '@nestjs/common';
describe('Mocked Execution Context', () => {
it('should have a fully mocked Execution Context', () => {
const mockExecutionContext = createMock<ExecutionContext>();
expect(mockExecutionContext.switchToHttp()).toBeDefined();
});
});
createMock generates all sub-properties as sinon.stub(), so you can chain method calls:
it('should correctly resolve mocked providers', async () => {
const request = {
key: 'val',
};
mockExecutionContext.switchToHttp.returns(
createMock<HttpArgumentsHost>({
getRequest: () => request,
}),
);
const mockResult = mockExecutionContext.switchToHttp().getRequest();
expect(mockResult).toBe(request);
});
You can also easily provide your own mocks:
const mockExecutionContext = createMock<ExecutionContext>({
switchToHttp: () => ({
getRequest: () => ({
headers: {
authorization: 'auth',
},
}),
getResponse: sinon.stub().returns({ data: 'res return data' }),
}),
});
::: warning Note When providing your own mocks, the number of times a parent mock function was called includes the times needed to set your mocks. :::
FAQs
Utilities for making testing [NestJS](https://docs.nestjs.com) applications easier.
The npm package @golevelup/ts-sinon receives a total of 14,496 weekly downloads. As such, @golevelup/ts-sinon popularity was classified as popular.
We found that @golevelup/ts-sinon demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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.

Product
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.