مرجع سريع

ورقة غش مكتبة اختبار جافاسكريبت Tape

دليل مرجعي سريع لمكتبة Tape الخفيفة لاختبار جافاسكريبت: التوكيدات، خطط الاختبار، دورة الحياة، والتحكم في الاختبارات.

· تاريخ النشر

Tape هي أداة اختبار خفيفة وبسيطة لـ JavaScript و Node.js تنتج مخرجات متوافقة تماماً مع معيار TAP (Test Anything Protocol).

مثال الاختبار الأساسي وخطة التشغيل (Test Example & Plan)

const test = require('tape')

test('basic mathematical operations', (t) => {
  t.plan(2)

  t.equal(1 + 1, 2, 'addition should compute sum')
  t.notEqual(2 * 3, 5, 'multiplication should not equal five')
})

طرق التوكيد والتحقق (Assertion Methods)

test('assertion reference', (t) => {
  t.plan(10)

  t.equal(actual, expected, 'values are equal (===)')
  t.notEqual(actual, expected, 'values are not equal')

  t.deepEqual(actual, expected, 'equivalent objects using deepEqual')
  t.notDeepEqual(actual, expected, 'objects are not deeply equal')

  t.looseEqual(actual, expected, 'values are loose equal (==)')
  t.notLooseEqual(actual, expected, 'values are not loose equal')

  t.ok(value, 'value is truthy')
  t.notOk(value, 'value is falsy')
  t.error(err, 'error argument is falsy')

  t.throws(fn, /ExpectedError/, 'function throws matching error')
  t.doesNotThrow(fn, 'function runs without throwing')
})

التحكم في دورة حياة الاختبار (Lifecycle & Control)

test('lifecycle control', (t) => {
  t.comment('informational log message')
  t.pass('explicit pass')
  t.fail('explicit failure')
  t.timeoutAfter(2000)
  t.skip('skipped assertion')
  t.end(err) // end test asynchronously
})
test.only('run only this focused test', (t) => {
  t.plan(1)
  t.ok(true)
})

أوراق غش ذات صلة

موضوعات ذات صلة