@epic-ai/nestjs-grpc-mock
v1.0.3
Published
This package provides an easy way to mock gRPC services in NestJS.
Downloads
26
Maintainers
Readme
NestJS gRPC Mock
This package provides an easy way to mock gRPC services in NestJS.
Installation
$ npm install --save-dev @epic-ai/nestjs-grpc-mock
or with yarn
$ yarn add -D @epic-ai/nestjs-grpc-mock
Usage
Example of testing a controller:
import { Test, TestingModule } from '@nestjs/testing';
import { ExampleController } from './example.controller';
import { ExampleService } from './example.service';
describe('ExampleController', () => {
let controller: ExampleController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ExampleController],
providers: [
{
provide: ExampleService,
useValue: GrpcMock.createMock<ExampleService>({
method: () => 'Mocked return value',
}),
}
],
}).compile();
controller = module.get<ExampleController>(ExampleController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
it('should return mocked value', async () => {
const result = await controller.method();
expect(result).toBe('Mocked return value');
});
});