2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-11-21 14:52:38 +00:00
|
|
|
// Copyright 2019 Allain Lalonde. All rights reserved. ISC License.
|
|
|
|
// This module is browser compatible.
|
|
|
|
|
|
|
|
/**
|
2024-03-26 02:57:40 +00:00
|
|
|
* This module provides Jest compatible expect assertion functionality.
|
2023-11-21 14:52:38 +00:00
|
|
|
*
|
2024-07-22 03:17:47 +00:00
|
|
|
* ```ts no-assert
|
|
|
|
* 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);
|
|
|
|
* ```
|
|
|
|
*
|
2024-03-26 02:57:40 +00:00
|
|
|
* Currently this module supports the following functions:
|
|
|
|
* - Common matchers:
|
2024-07-22 06:09:00 +00:00
|
|
|
* - {@linkcode Expected.toBe | toBe}
|
|
|
|
* - {@linkcode Expected.toEqual | toEqual}
|
|
|
|
* - {@linkcode Expected.toStrictEqual | toStrictEqual}
|
|
|
|
* - {@linkcode Expected.toMatch | toMatch}
|
|
|
|
* - {@linkcode Expected.toMatchObject | toMatchObject}
|
|
|
|
* - {@linkcode Expected.toBeDefined | toBeDefined}
|
|
|
|
* - {@linkcode Expected.toBeUndefined | toBeUndefined}
|
|
|
|
* - {@linkcode Expected.toBeNull | toBeNull}
|
|
|
|
* - {@linkcode Expected.toBeNaN | toBeNaN}
|
|
|
|
* - {@linkcode Expected.toBeTruthy | toBeTruthy}
|
|
|
|
* - {@linkcode Expected.toBeFalsy | toBeFalsy}
|
|
|
|
* - {@linkcode Expected.toContain | toContain}
|
|
|
|
* - {@linkcode Expected.toContainEqual | toContainEqual}
|
|
|
|
* - {@linkcode Expected.toHaveLength | toHaveLength}
|
|
|
|
* - {@linkcode Expected.toBeGreaterThan | toBeGreaterThan}
|
|
|
|
* - {@linkcode Expected.toBeGreaterThanOrEqual | toBeGreaterThanOrEqual}
|
|
|
|
* - {@linkcode Expected.toBeLessThan | toBeLessThan}
|
|
|
|
* - {@linkcode Expected.toBeLessThanOrEqual | toBeLessThanOrEqual}
|
|
|
|
* - {@linkcode Expected.toBeCloseTo | toBeCloseTo}
|
|
|
|
* - {@linkcode Expected.toBeInstanceOf | toBeInstanceOf}
|
|
|
|
* - {@linkcode Expected.toThrow | toThrow}
|
|
|
|
* - {@linkcode Expected.toHaveProperty | toHaveProperty}
|
2024-03-26 02:57:40 +00:00
|
|
|
* - Mock related matchers:
|
2024-07-22 06:09:00 +00:00
|
|
|
* - {@linkcode Expected.toHaveBeenCalled | toHaveBeenCalled}
|
|
|
|
* - {@linkcode Expected.toHaveBeenCalledTimes | toHaveBeenCalledTimes}
|
|
|
|
* - {@linkcode Expected.toHaveBeenCalledWith | toHaveBeenCalledWith}
|
|
|
|
* - {@linkcode Expected.toHaveBeenLastCalledWith | toHaveBeenLastCalledWith}
|
|
|
|
* - {@linkcode Expected.toHaveBeenNthCalledWith | toHaveBeenNthCalledWith}
|
|
|
|
* - {@linkcode Expected.toHaveReturned | toHaveReturned}
|
|
|
|
* - {@linkcode Expected.toHaveReturnedTimes | toHaveReturnedTimes}
|
|
|
|
* - {@linkcode Expected.toHaveReturnedWith | toHaveReturnedWith}
|
|
|
|
* - {@linkcode Expected.toHaveLastReturnedWith | toHaveLastReturnedWith}
|
|
|
|
* - {@linkcode Expected.toHaveNthReturnedWith | toHaveNthReturnedWith}
|
2024-03-26 02:57:40 +00:00
|
|
|
* - Asymmetric matchers:
|
2024-07-22 06:09:00 +00:00
|
|
|
* - {@linkcode expect.anything}
|
|
|
|
* - {@linkcode expect.any}
|
|
|
|
* - {@linkcode expect.arrayContaining}
|
2024-10-21 14:12:53 +00:00
|
|
|
* - {@linkcode expect.objectContaining}
|
2024-07-22 06:09:00 +00:00
|
|
|
* - {@linkcode expect.closeTo}
|
|
|
|
* - {@linkcode expect.stringContaining}
|
|
|
|
* - {@linkcode expect.stringMatching}
|
2024-03-26 02:57:40 +00:00
|
|
|
* - Utilities:
|
2024-10-25 08:29:40 +00:00
|
|
|
* - {@linkcode expect.assertions}
|
2024-07-22 06:09:00 +00:00
|
|
|
* - {@linkcode expect.addEqualityTester}
|
|
|
|
* - {@linkcode expect.extend}
|
2024-09-19 05:38:32 +00:00
|
|
|
* - {@linkcode expect.hasAssertions}
|
2023-11-21 14:52:38 +00:00
|
|
|
*
|
2024-03-26 02:57:40 +00:00
|
|
|
* Only these functions are still not available:
|
|
|
|
* - Matchers:
|
|
|
|
* - `toMatchSnapShot`
|
2024-09-19 05:38:32 +00:00
|
|
|
* - `toMatchInlineSnapshot`
|
|
|
|
* - `toThrowErrorMatchingSnapshot`
|
|
|
|
* - `toThrowErrorMatchingInlineSnapshot`
|
2024-03-26 02:57:40 +00:00
|
|
|
* - Asymmetric matchers:
|
|
|
|
* - `expect.not.objectContaining`
|
|
|
|
* - Utilities:
|
|
|
|
* - `expect.addSnapshotSerializer`
|
2023-11-21 14:52:38 +00:00
|
|
|
*
|
2024-07-22 03:17:47 +00:00
|
|
|
* The tracking issue to add support for unsupported parts of the API is
|
|
|
|
* {@link https://github.com/denoland/std/issues/3964}.
|
2024-01-31 22:19:46 +00:00
|
|
|
*
|
2024-07-22 03:17:47 +00:00
|
|
|
* This module is largely inspired by
|
|
|
|
* {@link https://github.com/allain/expect | x/expect} module by
|
|
|
|
* {@link https://github.com/allain | Allain Lalonde}.
|
2024-01-31 22:19:46 +00:00
|
|
|
*
|
|
|
|
* @module
|
2023-11-21 14:52:38 +00:00
|
|
|
*/
|
2024-07-22 03:17:47 +00:00
|
|
|
export * from "./expect.ts";
|
|
|
|
export * from "./fn.ts";
|