Logo di Nestjs Testing

Nestjs Testing

Organizzazione
nestjs
nestjs-testing

Unit, service and end-to-end tests for a NestJS application with @nestjs/testing - Test.createTestingModule, mocking and overriding providers and global guards, Supertest against the real app, signing test users in, SSE, test databases, Vitest in ESM projects (Jest in CommonJS ones). Use when writing, running or fixing tests in a NestJS application.

Panoramica

Pubblicato danestjs
Repositoryagent-skills
Nome della skillnestjs-testing
Stelle
176
Fork
5
File inclusi
1
LicenzaMIT
Link
  • Istruzioni in Markdown

    Un file SKILL.md che il modello carica quando serve, consumando token solo quando una richiesta è effettivamente pertinente.

  • Funziona con qualsiasi LLM

    Le skill IA sono in semplice Markdown, non in codice specifico di un fornitore, quindi funzionano con GPT, Claude, Gemini, Grok o un modello locale.

  • File inclusi: 1

    Script, template e riferimenti che il modello può leggere mentre lavora. I file sono di sola lettura e non vengono mai eseguiti.

  • Open source

    Pubblicata da nestjs su GitHub. Leggi i sorgenti prima di installarla.

Installazione

Installa la skill IA Nestjs Testing in TypingMind per usarla con qualsiasi LLM, oppure copiala in un altro agente in grado di leggere SKILL.md.

1

Installa in TypingMind

TypingMind installa una skill direttamente dalla sua cartella GitHub: legge SKILL.md, raccoglie i file delle risorse e salva il risultato in locale.

  1. Apri l'app e vai su Plugin → Skill.
  2. Scegli "Installa da GitHub".
  3. Incolla l'URL della cartella della skill riportato qui sotto e conferma.
    https://github.com/nestjs/agent-skills/tree/master/plugins/nestjs/skills/nestjs-testing
  4. Attiva la skill in ogni chat in cui vuoi averla a disposizione.
Plugin → Skill → Aggiungi skill → Da URL GitHub, poi incolla l'URL della cartella e premi Continua.
2

Installa in un altro agente

Qualsiasi agente che legge il formato Agent Skills può usare questa skill: copia la cartella della skill nella directory delle skill di quell'agente.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/nestjs/agent-skills.git /tmp/agent-skills
mkdir -p .claude/skills
cp -r /tmp/agent-skills/plugins/nestjs/skills/nestjs-testing .claude/skills/nestjs-testing
Dopo la copia, riavvia Claude Code per caricare la nuova skill.

Usala in TypingMind

Attiva Nestjs Testing in qualsiasi chat di TypingMind e al resto pensa il modello. Il nome e la descrizione della skill sono nel prompt di sistema e, non appena arriva una richiesta pertinente, il modello carica da solo le istruzioni complete: non devi mai richiamarla manualmente e non consuma token finché non viene effettivamente usata.

Il modello carica automaticamente Nestjs Testing non appena riceve una richiesta pertinente.

Funziona con qualsiasi modello IA

Le skill IA sono semplici istruzioni in Markdown, non codice specifico di un fornitore, quindi Nestjs Testing non è vincolata al modello per cui è stata scritta. Installala una sola volta in TypingMind e usala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modello locale che esegui tu, sempre con le tue chiavi API.

  • Caricata solo quando serve

    Il prompt di sistema contiene solo il nome e la descrizione. Le istruzioni vengono recuperate alla prima richiesta pertinente, quindi una skill inutilizzata non costa nulla.

  • Cambia modello durante la chat

    Poiché la skill è composta da istruzioni e non da codice, continua a funzionare anche se cambi modello: il nuovo modello legge lo stesso file SKILL.md.

Istruzioni della skill

Questo è il contenuto di SKILL.md che il modello carica. Leggilo prima dell'installazione: una skill è un insieme di istruzioni che il tuo modello seguirà.

Testing a NestJS app

Docs: https://docs.nestjs.com/fundamentals/testing.md. Recipes, each run with Vitest on the scaffold's config: references/testing.md.

Scope first. When the task says how to test, do that. When it says nothing, cover the behaviour you changed with focused tests (a unit test for a policy or a service rule, one e2e test per new route and its main error) rather than broad e2e suites, and verify the rest by running the app.

Pick the level

WhatHowSpeed
A policy, a pure function, a mappernew NotePolicy(fakeQuotas): no Nest at allms
A service's rulesTest.createTestingModule({ providers: [NotesService, { provide: NotesRepository, useValue: { findById: vi.fn() } }] })ms
A service with the real policiesthe above plus imports: [AuthorizationModule.forRoot()] and a stub AuthenticationContextms
A route as clients see itimports: [AppModule], Supertest on app.getHttpServer(), a fresh database100s of ms

Runner

  • Projects from nest new are ESM with Vitest (globals: true): npm test runs src/**/*.spec.ts, npm run test:e2e runs test/**/*.e2e-spec.ts. Mocks are vi.fn()/vi.spyOn(); relative imports end in .js. One file: npx vitest run src/notes/notes.service.spec.ts; one test: add -t "name".
  • CommonJS projects use Jest (jest.fn()). Follow the project's package.json.

Rules that save debugging time

  • The testing app doesn't run main.ts. Pipes, filters, prefixes and versioning set there are missing in tests: put them in one configureApp(app) that main.ts and the tests both call, or register them as APP_PIPE/APP_FILTER providers.
  • Module options are read when the module file is imported. Set env variables (database path, secrets) in the Vitest config's test.env, or import AppModule dynamically after setting them.
  • A global guard registered with useClass can't be replaced in tests. Neither .overrideGuard(ThrottlerGuard) nor .overrideProvider(ThrottlerGuard) touches { provide: APP_GUARD, useClass: ThrottlerGuard } (checked). Register it as ThrottlerGuard plus { provide: APP_GUARD, useExisting: ThrottlerGuard }, then .overrideProvider(ThrottlerGuard).useValue({ canActivate: () => true }) works. Or keep the guard and give tests a limit they won't reach.
  • Sign users in cheaply. Override PasswordHasher with new PasswordHasher({ logN: 10 }) (the default costs ~0.3 s and 128 MiB per hash); mint a bearer token with app.get(TokenService).issue(user.id); run service code as a user with app.get(AuthenticationContext).run({ user }, fn). Keep one test that signs in through the real route.
  • One database per test file. Vitest runs files in parallel: a shared SQLite file or schema makes them interfere. Create a temporary file (or schema) per file, apply the migrations, delete it afterwards.
  • No ports, no leftovers. await app.init() and request(app.getHttpServer()) need no port; afterAll(() => app.close()) closes connections and timers. Leave no server or watcher running when you finish.
  • Time-dependent code (reminders, expiry, rate windows): inject a clock or the delay, rather than sleeping in tests.
  • Test what the client sees in e2e tests: status codes, bodies, headers. Assert the exact status the contract names (expect(201) on a create, expect(200) on a sign-in), which also catches @Post()'s default 201.

When tests fail to start

  • Nest can't resolve dependencies of NotesService (?) in a unit test: the testing module lacks a provider. Add a useValue stub for it, or useMocker(() => ({})) for everything missing.
  • The app works but the test module doesn't: something is registered in main.ts only (see above), or env variables are read before the test sets them.

File inclusi

Il modello legge questi file quando servono, mentre la skill è caricata. Sono accessibili in sola lettura e non vengono mai eseguiti.

Domande frequenti

Cosa fa la skill IA Nestjs Testing?

Unit, service and end-to-end tests for a NestJS application with @nestjs/testing - Test.createTestingModule, mocking and overriding providers and global guards, Supertest against the real app, signing test users in, SSE, test databases, Vitest in ESM projects (Jest in CommonJS ones). Use when writing, running or fixing tests in a NestJS application.

Perché usare Nestjs Testing su TypingMind?

Perché la installi una volta e la usi con qualsiasi modello. Nestjs Testing è scritta in semplice Markdown anziché in codice specifico di un fornitore, quindi la stessa skill funziona con GPT-5, Claude, Gemini, Grok o un modello locale, e puoi cambiare modello durante la chat senza che la skill smetta di funzionare. TypingMind usa le tue chiavi API, quindi paghi direttamente i fornitori anziché un abbonamento per posto utente, e le tue skill e chat restano nel tuo spazio di archiviazione.

Come installo Nestjs Testing in TypingMind?

Apri Plugin → Skill → Installa da GitHub in TypingMind e incolla https://github.com/nestjs/agent-skills/tree/master/plugins/nestjs/skills/nestjs-testing. TypingMind legge il file SKILL.md, include i file associati e installa la skill, che puoi abilitare per ogni singola chat.

Quali modelli IA possono usare Nestjs Testing?

Qualsiasi modello che colleghi a TypingMind. Le skill IA sono semplici istruzioni in Markdown anziché codice specifico di un fornitore, quindi GPT, Claude, Gemini, Grok e i modelli locali possono tutti caricare questa skill quando una richiesta corrisponde al suo scopo.

Quanti modelli IA posso usare con Nestjs Testing?

Quanti ne vuoi. Se un modello supporta le skill, puoi usarlo con Nestjs Testing: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama e molti altri, tutti su TypingMind con le tue chiavi API.

La skill IA Nestjs Testing è gratuita?

Sì. È pubblicata su GitHub da nestjs con licenza MIT. Paghi solo il tuo fornitore IA per i token che usi.

Cosa sono le skill IA?

Una skill IA è un pacchetto di istruzioni riutilizzabili che insegna a un modello IA come svolgere un'attività specifica. Segue il formato aperto Agent Skills: un file SKILL.md con un nome e una descrizione, più eventuali script, template o file di riferimento di cui il modello potrebbe aver bisogno. Il modello legge le istruzioni solo quando la tua richiesta corrisponde alla skill, quindi una skill installata non comporta costi finché non viene usata.

In cosa si differenziano le skill IA dai plugin o dai server MCP?

Un plugin o un server MCP fornisce a un modello nuovi strumenti da richiamare: codice che viene eseguito da qualche parte e restituisce un risultato. Una skill IA, invece, fornisce al modello conoscenze e procedure: come affrontare un'attività, quali passaggi seguire e quali caratteristiche deve avere un buon output. Le skill sono semplici istruzioni in Markdown, quindi non richiedono server, chiavi API né ambienti di esecuzione e funzionano con qualsiasi modello.

Elenco completo

Crea subito il tuo spazio di lavoro AI

Iscriviti alla nostra newsletter per ricevere aggiornamenti sulle nuove funzionalità e sulle prossime iniziative a premi 👇