mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 12:49:10 +00:00
rename(std/testing): rename assert*Contains to assert*Includes (#7951)
This commit renames two assertion functions to better align with JS API: - assertStringContains -> assertStringIncludes - assertArrayContains -> assertArrayIncludes
This commit is contained in:
parent
305a9c04ba
commit
ae86cbb551
16 changed files with 60 additions and 60 deletions
|
@ -18,12 +18,12 @@ pretty-printed diff of failing assertion.
|
|||
and `expected` are equal.
|
||||
- `assertStrictEquals()` - Compares `actual` and `expected` strictly, therefore
|
||||
for non-primitives the values must reference the same instance.
|
||||
- `assertStringContains()` - Make an assertion that `actual` contains
|
||||
- `assertStringIncludes()` - Make an assertion that `actual` includes
|
||||
`expected`.
|
||||
- `assertMatch()` - Make an assertion that `actual` match RegExp `expected`.
|
||||
- `assertNotMatch()` - Make an assertion that `actual` not match RegExp
|
||||
`expected`.
|
||||
- `assertArrayContains()` - Make an assertion that `actual` array contains the
|
||||
- `assertArrayIncludes()` - Make an assertion that `actual` array includes the
|
||||
`expected` values.
|
||||
- `assertObjectMatch()` - Make an assertion that `actual` object match
|
||||
`expected` subset object
|
||||
|
|
|
@ -330,10 +330,10 @@ export function assertNotStrictEquals(
|
|||
}
|
||||
|
||||
/**
|
||||
* Make an assertion that actual contains expected. If not
|
||||
* Make an assertion that actual includes expected. If not
|
||||
* then thrown.
|
||||
*/
|
||||
export function assertStringContains(
|
||||
export function assertStringIncludes(
|
||||
actual: string,
|
||||
expected: string,
|
||||
msg?: string,
|
||||
|
@ -347,26 +347,26 @@ export function assertStringContains(
|
|||
}
|
||||
|
||||
/**
|
||||
* Make an assertion that `actual` contains the `expected` values.
|
||||
* Make an assertion that `actual` includes the `expected` values.
|
||||
* If not then an error will be thrown.
|
||||
*
|
||||
* Type parameter can be specified to ensure values under comparison have the same type.
|
||||
* For example:
|
||||
*```ts
|
||||
*assertArrayContains<number>([1, 2], [2])
|
||||
*assertArrayIncludes<number>([1, 2], [2])
|
||||
*```
|
||||
*/
|
||||
export function assertArrayContains(
|
||||
export function assertArrayIncludes(
|
||||
actual: ArrayLike<unknown>,
|
||||
expected: ArrayLike<unknown>,
|
||||
msg?: string,
|
||||
): void;
|
||||
export function assertArrayContains<T>(
|
||||
export function assertArrayIncludes<T>(
|
||||
actual: ArrayLike<T>,
|
||||
expected: ArrayLike<T>,
|
||||
msg?: string,
|
||||
): void;
|
||||
export function assertArrayContains(
|
||||
export function assertArrayIncludes(
|
||||
actual: ArrayLike<unknown>,
|
||||
expected: ArrayLike<unknown>,
|
||||
msg?: string,
|
||||
|
@ -388,7 +388,7 @@ export function assertArrayContains(
|
|||
return;
|
||||
}
|
||||
if (!msg) {
|
||||
msg = `actual: "${_format(actual)}" expected to contain: "${
|
||||
msg = `actual: "${_format(actual)}" expected to include: "${
|
||||
_format(expected)
|
||||
}"\nmissing: ${_format(missing)}`;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import {
|
||||
_format,
|
||||
assert,
|
||||
assertArrayContains,
|
||||
assertArrayIncludes,
|
||||
assertEquals,
|
||||
AssertionError,
|
||||
assertMatch,
|
||||
|
@ -11,7 +11,7 @@ import {
|
|||
assertNotStrictEquals,
|
||||
assertObjectMatch,
|
||||
assertStrictEquals,
|
||||
assertStringContains,
|
||||
assertStringIncludes,
|
||||
assertThrows,
|
||||
assertThrowsAsync,
|
||||
equal,
|
||||
|
@ -161,12 +161,12 @@ Deno.test("testingNotEquals", function (): void {
|
|||
});
|
||||
|
||||
Deno.test("testingAssertStringContains", function (): void {
|
||||
assertStringContains("Denosaurus", "saur");
|
||||
assertStringContains("Denosaurus", "Deno");
|
||||
assertStringContains("Denosaurus", "rus");
|
||||
assertStringIncludes("Denosaurus", "saur");
|
||||
assertStringIncludes("Denosaurus", "Deno");
|
||||
assertStringIncludes("Denosaurus", "rus");
|
||||
let didThrow;
|
||||
try {
|
||||
assertStringContains("Denosaurus", "Raptor");
|
||||
assertStringIncludes("Denosaurus", "Raptor");
|
||||
didThrow = false;
|
||||
} catch (e) {
|
||||
assert(e instanceof AssertionError);
|
||||
|
@ -178,14 +178,14 @@ Deno.test("testingAssertStringContains", function (): void {
|
|||
Deno.test("testingArrayContains", function (): void {
|
||||
const fixture = ["deno", "iz", "luv"];
|
||||
const fixtureObject = [{ deno: "luv" }, { deno: "Js" }];
|
||||
assertArrayContains(fixture, ["deno"]);
|
||||
assertArrayContains(fixtureObject, [{ deno: "luv" }]);
|
||||
assertArrayContains(
|
||||
assertArrayIncludes(fixture, ["deno"]);
|
||||
assertArrayIncludes(fixtureObject, [{ deno: "luv" }]);
|
||||
assertArrayIncludes(
|
||||
Uint8Array.from([1, 2, 3, 4]),
|
||||
Uint8Array.from([1, 2, 3]),
|
||||
);
|
||||
assertThrows(
|
||||
(): void => assertArrayContains(fixtureObject, [{ deno: "node" }]),
|
||||
(): void => assertArrayIncludes(fixtureObject, [{ deno: "node" }]),
|
||||
AssertionError,
|
||||
`actual: "[
|
||||
{
|
||||
|
@ -194,7 +194,7 @@ Deno.test("testingArrayContains", function (): void {
|
|||
{
|
||||
deno: "Js",
|
||||
},
|
||||
]" expected to contain: "[
|
||||
]" expected to include: "[
|
||||
{
|
||||
deno: "node",
|
||||
},
|
||||
|
@ -210,7 +210,7 @@ missing: [
|
|||
Deno.test("testingAssertStringContainsThrow", function (): void {
|
||||
let didThrow = false;
|
||||
try {
|
||||
assertStringContains("Denosaurus from Jurassic", "Raptor");
|
||||
assertStringIncludes("Denosaurus from Jurassic", "Raptor");
|
||||
} catch (e) {
|
||||
assert(
|
||||
e.message ===
|
||||
|
@ -715,7 +715,7 @@ Deno.test({
|
|||
fn(): void {
|
||||
assertEquals<string>("hello", "hello");
|
||||
assertNotEquals<number>(1, 2);
|
||||
assertArrayContains<boolean>([true, false], [true]);
|
||||
assertArrayIncludes<boolean>([true, false], [true]);
|
||||
const value = { x: 1 };
|
||||
assertStrictEquals<typeof value>(value, value);
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue