@epic-ai/nestjs-grpc-mock
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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');
  });
});

Readme

Keywords

Package Sidebar

Install

npm i @epic-ai/nestjs-grpc-mock

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

29.2 kB

Total Files

13

Last publish

Collaborators

  • alexanderclaas