Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nestjs/testing

Package Overview
Dependencies
Maintainers
1
Versions
338
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestjs/testing

Nest - modern, fast, powerful node.js web framework (@testing)

  • 10.4.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.7M
increased by9.06%
Maintainers
1
Weekly downloads
 
Created

What is @nestjs/testing?

The @nestjs/testing package provides a set of utilities designed to help with the testing of NestJS applications. It simplifies the process of setting up a testing environment, allowing developers to focus on writing their tests. This package is specifically tailored for NestJS, making it easier to test modules, services, controllers, and other components within a NestJS application.

What are @nestjs/testing's main functionalities?

Unit Testing Controllers

This example demonstrates how to set up a unit test for a controller in NestJS using the @nestjs/testing package. It shows the creation of a testing module, mocking dependencies, and asserting the controller's existence.

import { Test, TestingModule } from '@nestjs/testing';
import { CatsController } from './cats.controller';
import { CatsService } from './cats.service';

describe('CatsController', () => {
  let controller: CatsController;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      controllers: [CatsController],
      providers: [{ provide: CatsService, useValue: {} }],
    }).compile();

    controller = module.get<CatsController>(CatsController);
  });

  it('should be defined', () => {
    expect(controller).toBeDefined();
  });
});

Integration Testing

This code snippet illustrates how to perform an integration test on a NestJS application. It involves setting up the entire application within the test environment and using the 'supertest' package to make HTTP requests to test the application's endpoints.

import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from './../src/app.module';

describe('Cats', () => {
  let app: INestApplication;

  beforeAll(async () => {
    const moduleFixture: TestingModule = await Test.createTestingModule({
      imports: [AppModule],
    }).compile();

    app = moduleFixture.createNestApplication();
    await app.init();
  });

  it('/GET cats', () => {
    return request(app.getHttpServer())
      .get('/cats')
      .expect(200)
      .expect('This action returns all cats');
  });
});

Other packages similar to @nestjs/testing

FAQs

Package last updated on 25 Nov 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc