Saltar al contenido

Referencia de la API node:test

Cómo admite Elide la API del ejecutor test de Node: pruebas, suites, hooks y mocks se ejecutan con elide test; run(), mock.module() y snapshots no existen.

Leer sin conexiónelide help --lang es api-node-test

En esta página

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

javascript
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);
  });
});
utf-8 · javascript · Líneas: 11

Superficie disponible

Área Miembros
Pruebas y suites test / it, describe / suite, además de .skip, .todo y .only
Hooks before, after, beforeEach, afterEach
Contexto de prueba t.assert, t.test, hooks, t.diagnostic, t.plan, t.skip, t.todo, t.mock, t.signal
Mocks mock.fn, mock.method, mocks de propiedades/accesores, temporizadores falsos, reinicio y restauración
Aserciones del módulo test.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:

Terminal
bash
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

Export Kind Status Notes
test() function Full Define and run a test case
it() function Full Alias for test()
describe() function Full Group tests into a suite
suite() function Full Alias for describe()
before() function Full Register a function to run before all tests in the current suite
after() function Full Register a function to run after all tests in the current suite
beforeEach() function Full Register a function to run before each test in the current suite
afterEach() function Full Register a function to run after each test in the current suite
mock property Full The mock object for creating spies and mocking timers

Not implemented

expectFailure, getTestContext.

¿Te resultó útil esta página?