انتقل إلى المحتوى

مرجع واجهة ⁦node:test⁩

تسجيل الاختبارات في ⁦Node.js⁩ والمجموعات والخطافات والتأكيدات والمحاكاة

في هذه الصفحة

استورد واجهة تسجيل الاختبارات المتوافقة مع ⁦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

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.

هل كانت هذه الصفحة مفيدة؟