Перейти к содержимому

Справочник API node:test

Как Elide поддерживает API test из Node: тесты, наборы, хуки и моки запускаются через elide test; run(), mock.module() и снапшоты недоступны.

Читать офлайнelide help --lang ru api-node-test

На этой странице

Импортируйте совместимый с Node API регистрации тестов из 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 · Строк: 11

Доступные возможности

Область Элементы
Тесты и наборы test / it, describe / suite, а также .skip, .todo и .only
Хуки before, after, beforeEach, afterEach
Контекст теста t.assert, t.test, хуки, t.diagnostic, t.plan, t.skip, t.todo, t.mock, t.signal
Моки mock.fn, mock.method, моки свойств/аксессоров, поддельные таймеры, сброс и восстановление
Утверждения модуля test.assert

Утверждения снимков, mock.module() и программная точка входа run() не реализованы.

Запуск тестов

Запускайте файлы node:test командой elide test, которая также принимает явный файл:

Терминал
bash
elide test ./math.test.mjs

elide run регистрирует тесты, не запуская их, и выводит команду elide test, которую следует использовать вместо этого.

См. также

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.

Была ли эта страница полезной?