Spec-Zone.ru › Deno 2

@std/expect

Обзор

Этот модуль предоставляет совместимые с Jest функции для проверки утверждений с помощью expect.

import { expect } from "@std/expect";

const x = 6 * 7;
expect(x).toEqual(42);
expect(x).not.toEqual(0);

await expect(Promise.resolve(x)).resolves.toEqual(42);

В настоящее время модуль поддерживает следующие функции:

  • Общие матчеры:
    • toBe
    • toEqual
    • toStrictEqual
    • toMatch
    • toMatchObject
    • toBeDefined
    • toBeUndefined
    • toBeNull
    • toBeNaN
    • toBeTruthy
    • toBeFalsy
    • toContain
    • toContainEqual
    • toHaveLength
    • toBeGreaterThan
    • toBeGreaterThanOrEqual
    • toBeLessThan
    • toBeLessThanOrEqual
    • toBeCloseTo
    • toBeInstanceOf
    • toThrow
    • toHaveProperty
    • toMatchSnapshot
    • toMatchInlineSnapshot
  • Матчеры для моков:
    • toHaveBeenCalled
    • toHaveBeenCalledTimes
    • toHaveBeenCalledWith
    • toHaveBeenLastCalledWith
    • toHaveBeenNthCalledWith
    • toHaveReturned
    • toHaveReturnedTimes
    • toHaveReturnedWith
    • toHaveLastReturnedWith
    • toHaveNthReturnedWith
  • Асимметричные матчеры:
    • expect.anything
    • expect.any
    • expect.arrayContaining
    • expect.not.arrayContaining
    • expect.objectContaining
    • expect.not.objectContaining
    • expect.closeTo
    • expect.stringContaining
    • expect.not.stringContaining
    • expect.stringMatching
    • expect.not.stringMatching
  • Утилиты:
    • expect.addSnapshotSerializer
    • expect.assertions
    • expect.addEqualityTester
    • expect.extend
    • expect.hasAssertions

Пока доступны не все функции:

  • Матчеры:
    • toThrowErrorMatchingSnapshot
    • toThrowErrorMatchingInlineSnapshot

За ходом добавления поддержки неподдерживаемых частей API можно следить в задаче.

Этот модуль во многом вдохновлён модулем x/expect, созданным Алленом Лалондом.

Добавление в проект

›_
deno add jsr:@std/expect

См. все символы в @std/expect на

© 2018–2025 the Deno authors
Licensed under the MIT License.
https://docs.deno.com/runtime/reference/std/expect

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API