Saltar al contenido

Referencia de la API node:test

Registro de pruebas, suites, hooks, aserciones y mocks de Node.js

En esta página

Importe la API de registro de pruebas compatible con Node mediante node:test:

import test, { describe, it } from "node:test";

test("addition", (t) => {
  t.assert.strictEqual(1 + 1, 2);
});

describe("math", () => {
  it("multiplies", (t) => {
    t.assert.strictEqual(2 * 3, 6);
  });
});

Superficie disponible

ÁreaMiembros
Pruebas y suitestest / it, describe / suite, además de .skip, .todo y .only
Hooksbefore, after, beforeEach, afterEach
Contexto de pruebat.assert, t.test, hooks, t.diagnostic, t.plan, t.skip, t.todo, t.mock, t.signal
Mocksmock.fn, mock.method, mocks de propiedades/accesores, temporizadores falsos, reinicio y restauración
Aserciones del módulotest.assert

Las aserciones de instantáneas, mock.module() y el punto de entrada programático run() no están implementados.

Ejecutar pruebas

Ejecute los archivos de node:test con elide test, que también acepta un archivo explícito:

elide test ./math.test.mjs

elide run registra las pruebas sin ejecutarlas e imprime el comando elide test que debe usarse en su lugar.

Véase también

Reference

Status: Partial · Not measured · since 1.1.0

Exports

ExportKindStatusNotes
test()functionFullDefine and run a test case
it()functionFullAlias for test()
describe()functionFullGroup tests into a suite
suite()functionFullAlias for describe()
before()functionFullRegister a function to run before all tests in the current suite
after()functionFullRegister a function to run after all tests in the current suite
beforeEach()functionFullRegister a function to run before each test in the current suite
afterEach()functionFullRegister a function to run after each test in the current suite
mockpropertyFullThe mock object for creating spies and mocking timers

Not implemented

expectFailure, getTestContext.

¿Te resultó útil esta página?