Skip to main content
ProductsDesktop toolsTASTECADDrawing reviewTASTEFILESFile managementTASTEFTPFile transferTASTESSHRemote workspaceTASTEZIPCompression and extractionTASTEWINMFile managementDeveloper toolsTASTECODERust integrated development environmentTASTESTUDIOIntegrated development and test environmentTASTEETLData integration (ETL)ServersTASTEREMOTERemote desktop serverTASTEGEOGeospatial serverTASTEMAILMail workspaceInvestingTASTESTOCKStock auto-trading desktop appGet startedDownloadsDocumentationBuyAll products
Marketplace
News
TechNewsToday's dev newsDeveloper docsProgramming languagesRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngularServer frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressApp & desktop frameworksTauriFlutterReact NativeElectronAlgorithmsAlgorithm basicsCore algorithmsAdvanced algorithmsPractical algorithms
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcaseCommunity guide
Work with usTech transferWebsite buildDesktop app buildRelease and payment pipelineSales partnerContact
ServicesRemote desktopCustom installer packages
TASTEDEV
Products

Desktop tools

TASTECADComplex drawings, opened with easeTASTEFILESJust the files you need, as fast as possibleTASTEFTPThe tidiest path for your filesTASTESSHA stronger link between you and your serversTASTEZIPPack faster, unpack saferTASTEWINMA keyboard-first file manager with two panes

Developer tools

TASTECODEEdit, build, debug and test Rust apps in one windowTASTESTUDIOFrom editing to remote tests and approved AI fixesTASTEETLMove data while you watch the values

Servers

TASTEREMOTEA remote desktop you run on your own serverTASTEGEORebuilding a GeoServer-compatible geospatial server in RustTASTEMAILTake back control of your email

Investing

TASTESTOCKStock auto-trading that follows the rules you set: when, and what

Get started

DownloadsLatest builds of every productDocsHow to use each productBuySubscriptions and perpetual licencesAll productsEvery product at a glance
All products
MarketplaceNews
Tech

News

Today's dev newsOfficial announcements on languages, frameworks, GitHub and AIDeveloper docsGuides to languages, frameworks and algorithms

Programming languages

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Frameworks

Web front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngular
Server frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
App & desktop frameworksTauriFlutterReact NativeElectron

Algorithms

Algorithm basicsComplexity analysis · Sorting · Searching · Basic data structures · Trees and heapsCore algorithmsGraph traversal · Shortest paths & minimum spanning trees · Dynamic programming · Greedy algorithms · Divide and conquer · BacktrackingAdvanced algorithmsString algorithms · Math and number theory · Bit manipulation · Segment trees · Union-findPractical algorithmsCoding interview strategy · LRU cache · Rate limiting · Consistent hashing
All development docs
Community
ProjectsDiscover builders and their workDevelopment logsDecisions and lessons learnedPromptsReusable instructionsAI tool issuesProblems and workarounds for Claude, Codex, GeminiShowcaseFinished resultsCommunity guideHow we build in the open
Work with us
Tech transferNative apps in Rust and eguiWebsite build10 languages, accounts, docs and downloadsDesktop app buildRust and egui, no WebViewRelease and payment pipelineSigning, MSI, deb, rpm, AppImage, hashesSales partnerRecommend us and earn 30%ContactBuilds, partnerships and investment
Services
Remote desktopReach your computer from a browserCustom installer packagesOnly the features you need, settings preloaded
Buy
EN
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Log in
Log in
TASTEDEV

From small tools to better development.

support@tastedev.netSupport TASTEDEV
ProductsProduct lineupBuyDocsDownloadsMarketplaceSupport
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcase
PoliciesAbout usPrivacy policyTerms of serviceSubscription termsRefund policyCommunity guidelines
AccountLog inSign up
Visitors
Today
Yesterday
Total views
Company
GXSOFT
Representative
CHOI YOUNG GU
Business registration number
853-44-00368
Address
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Phone
+82-10-4404-1523
Email
whitecalvin@tastedev.net
Privacy officer
CHOI YOUNG GU

© 2026 TASTEDEVProduct information is based on verified development sources.Released · improving

NestJS · Express docs
NestJS · Express
Getting Started with NestJS and ExpressProject StructureCore ConceptsValidation, Configuration and DatabasesTestingDeployment
Discussions

NestJS · Express guide · 5/6

Testing

Projects created with nest new come with Jest, Supertest and Nest's testing package, @nestjs/testing, already configured. This chapter covers unit tests for services and controllers, end-to-end tests that boot the whole application, and testing a plain Express app with Supertest.

Running tests

Unit tests are the *.spec.ts files inside src; end-to-end tests are the *.e2e-spec.ts files in test, which use their own Jest config, test/jest-e2e.json.

npm run test         # unit tests
npm run test:watch   # re-run on file changes
npm run test:cov     # coverage report
npm run test:e2e     # end-to-end tests

Unit testing a service

A service without dependencies can be tested like any class, by calling new. When it has dependencies, build a testing module with Test.createTestingModule and replace real providers with fakes.

// src/users/users.service.spec.ts
import { Test } from "@nestjs/testing";
import { getRepositoryToken } from "@nestjs/typeorm";
import { User } from "./entities/user.entity";
import { UsersService } from "./users.service";

describe("UsersService", () => {
  let service: UsersService;
  const repository = { find: jest.fn(), create: jest.fn(), save: jest.fn() };

  beforeEach(async () => {
    const moduleRef = await Test.createTestingModule({
      providers: [UsersService, { provide: getRepositoryToken(User), useValue: repository }],
    }).compile();

    service = moduleRef.get(UsersService);
  });

  it("returns every user", async () => {
    repository.find.mockResolvedValue([{ id: 1, name: "Kim" }]);
    await expect(service.findAll()).resolves.toHaveLength(1);
  });
});

getRepositoryToken(User) is the injection token that @InjectRepository(User) looks up, so the service logic runs without a database.

Unit testing a controller

For controllers, fake the service. When you register the real provider and want to swap it, use overrideProvider.

// src/users/users.controller.spec.ts
import { Test } from "@nestjs/testing";
import { UsersController } from "./users.controller";
import { UsersService } from "./users.service";

describe("UsersController", () => {
  it("delegates to the service", async () => {
    const usersService = { findAll: jest.fn().mockResolvedValue([]) };

    const moduleRef = await Test.createTestingModule({
      controllers: [UsersController],
      providers: [UsersService],
    })
      .overrideProvider(UsersService)
      .useValue(usersService)
      .compile();

    const controller = moduleRef.get(UsersController);
    await controller.findAll();
    expect(usersService.findAll).toHaveBeenCalled();
  });
});

End-to-end tests with Supertest

An e2e test builds the app from real modules and sends HTTP requests with Supertest. Apply the same global setup as main.ts, such as pipes, to the test app.

// test/users.e2e-spec.ts
import { INestApplication, ValidationPipe } from "@nestjs/common";
import { Test } from "@nestjs/testing";
import request from "supertest";
import { AppModule } from "../src/app.module";

describe("Users (e2e)", () => {
  let app: INestApplication;

  beforeAll(async () => {
    const moduleRef = await Test.createTestingModule({ imports: [AppModule] }).compile();
    app = moduleRef.createNestApplication();
    app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
    await app.init();
  });

  afterAll(async () => {
    await app.close();
  });

  it("rejects an invalid body", () => {
    return request(app.getHttpServer()).post("/users").send({ name: "" }).expect(400);
  });
});

app.getHttpServer() returns the underlying HTTP server, so no port is needed. For e2e tests that touch a database, use a dedicated test database or start a throwaway container per run with a tool such as Testcontainers, keeping production data out of reach.

Testing an Express app

Express works the same way. If app.js only exports the app, as in the project structure chapter, Supertest can call it directly.

npm i -D jest supertest
// test/users.test.js
const request = require("supertest");
const app = require("../src/app");

test("GET /users/1 returns the user", async () => {
  const response = await request(app).get("/users/1").expect(200);
  expect(response.body.id).toBe("1");
});

Node's built-in test runner, node:test, also pairs well with Supertest.

Summary

  • Nest projects come with Jest for unit tests and Supertest for end-to-end tests.
  • Build test modules with Test.createTestingModule and replace dependencies with useValue or overrideProvider.
  • E2E tests use createNestApplication() and app.getHttpServer() to exercise the real request pipeline, with the same global setup as production.
  • Splitting app from listen makes Express apps easy to test with Supertest.
Questions about this chapter?
Previous chapterValidation, Configuration and DatabasesNext chapterDeployment

0 comments

Top commentsNewest first

Sign in · Sign in to leave a comment.