استورد واجهة تسجيل الاختبارات المتوافقة مع Node باستخدام 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);
});
});الواجهة المتاحة
| المجال | العناصر |
|---|---|
| الاختبارات والمجموعات | 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، الذي يقبل أيضًا ملفًا صريحًا:
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.