Skip to content

Commit

Permalink
rename(testing): rename assert*Contains to assert*Includes (denoland/…
Browse files Browse the repository at this point in the history
…deno#7951)

This commit renames two assertion functions to better align with JS API:
- assertStringContains -> assertStringIncludes
- assertArrayContains -> assertArrayIncludes
  • Loading branch information
timreichen authored and denobot committed Feb 1, 2021
1 parent 267c76c commit 55a7adb
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions examples/xeval_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { decode, encode } from "../encoding/utf8.ts";
import {
assert,
assertEquals,
assertStringContains,
assertStringIncludes,
} from "../testing/asserts.ts";
import { dirname, fromFileUrl } from "../path/mod.ts";

Expand Down Expand Up @@ -66,6 +66,6 @@ Deno.test("xevalCliSyntaxError", async function (): Promise<void> {
});
assertEquals(await p.status(), { code: 1, success: false });
assertEquals(decode(await p.output()), "");
assertStringContains(decode(await p.stderrOutput()), "SyntaxError");
assertStringIncludes(decode(await p.stderrOutput()), "SyntaxError");
p.close();
});
4 changes: 2 additions & 2 deletions fs/empty_dir_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
assert,
assertEquals,
assertStringContains,
assertStringIncludes,
assertThrows,
assertThrowsAsync,
} from "../testing/asserts.ts";
Expand Down Expand Up @@ -231,7 +231,7 @@ for (const s of scenes) {
assert(p.stdout);
const output = await p.output();
p.close();
assertStringContains(new TextDecoder().decode(output), s.output);
assertStringIncludes(new TextDecoder().decode(output), s.output);
} catch (err) {
await Deno.remove(testfolder, { recursive: true });
throw err;
Expand Down
4 changes: 2 additions & 2 deletions fs/exists_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { assertEquals, assertStringContains } from "../testing/asserts.ts";
import { assertEquals, assertStringIncludes } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { exists, existsSync } from "./exists.ts";

Expand Down Expand Up @@ -130,7 +130,7 @@ for (const s of scenes) {

const output = await p.output();
p.close();
assertStringContains(new TextDecoder().decode(output), s.output);
assertStringIncludes(new TextDecoder().decode(output), s.output);
});
// done
}
4 changes: 2 additions & 2 deletions fs/expand_glob_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { decode } from "../encoding/utf8.ts";
import {
assert,
assertEquals,
assertStringContains,
assertStringIncludes,
} from "../testing/asserts.ts";
import {
fromFileUrl,
Expand Down Expand Up @@ -126,7 +126,7 @@ Deno.test("expandGlobPermError", async function (): Promise<void> {
});
assertEquals(await p.status(), { code: 1, success: false });
assertEquals(decode(await p.output()), "");
assertStringContains(
assertStringIncludes(
decode(await p.stderrOutput()),
"Uncaught PermissionDenied",
);
Expand Down
4 changes: 2 additions & 2 deletions http/server_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
assert,
assertEquals,
assertMatch,
assertStringContains,
assertStringIncludes,
assertThrowsAsync,
} from "../testing/asserts.ts";
import {
Expand Down Expand Up @@ -498,7 +498,7 @@ Deno.test({
const nread = await conn.read(res);
assert(nread !== null);
const resStr = new TextDecoder().decode(res.subarray(0, nread));
assertStringContains(resStr, "/hello");
assertStringIncludes(resStr, "/hello");
server.close();
await p;
// Client connection should still be open, verify that
Expand Down
4 changes: 2 additions & 2 deletions node/module_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {
assert,
assertEquals,
assertStringContains,
assertStringIncludes,
} from "../testing/asserts.ts";

import * as path from "../path/mod.ts";
Expand Down Expand Up @@ -67,6 +67,6 @@ Deno.test("requireStack", function () {
try {
hello();
} catch (e) {
assertStringContains(e.stack, "/tests/cjs/cjs_throw.js");
assertStringIncludes(e.stack, "/tests/cjs/cjs_throw.js");
}
});
4 changes: 2 additions & 2 deletions testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions testing/asserts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)}`;
}
Expand Down
26 changes: 13 additions & 13 deletions testing/asserts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
_format,
assert,
assertArrayContains,
assertArrayIncludes,
assertEquals,
AssertionError,
assertMatch,
Expand All @@ -11,7 +11,7 @@ import {
assertNotStrictEquals,
assertObjectMatch,
assertStrictEquals,
assertStringContains,
assertStringIncludes,
assertThrows,
assertThrowsAsync,
equal,
Expand Down Expand Up @@ -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);
Expand All @@ -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: "[
{
Expand All @@ -194,7 +194,7 @@ Deno.test("testingArrayContains", function (): void {
{
deno: "Js",
},
]" expected to contain: "[
]" expected to include: "[
{
deno: "node",
},
Expand All @@ -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 ===
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 55a7adb

Please sign in to comment.