Перейти до вмісту

Довідник API node:test

Як Elide підтримує API test з Node: тести, набори, хуки й моки запускаються через elide test; run(), mock.module() і знімки недоступні.

Читати офлайнelide help --lang uk 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.

Чи була ця сторінка корисною?