mirror of
https://github.com/denoland/deno.git
synced 2025-01-11 08:33:43 -05:00
fix(std/node): misnamed assert exports (#7123)
This commit is contained in:
parent
5adb6cba3e
commit
87b1b8c461
4 changed files with 147 additions and 4 deletions
|
@ -2,14 +2,21 @@ import {
|
||||||
assertEquals,
|
assertEquals,
|
||||||
assertNotEquals,
|
assertNotEquals,
|
||||||
assertStrictEquals,
|
assertStrictEquals,
|
||||||
|
assertNotStrictEquals,
|
||||||
assertMatch,
|
assertMatch,
|
||||||
assertThrows,
|
assertThrows,
|
||||||
} from "../testing/asserts.ts";
|
} from "../testing/asserts.ts";
|
||||||
|
|
||||||
export { assert, fail } from "../testing/asserts.ts";
|
export {
|
||||||
|
assert as default,
|
||||||
|
assert as ok,
|
||||||
|
assert,
|
||||||
|
fail,
|
||||||
|
} from "../testing/asserts.ts";
|
||||||
|
|
||||||
export const equal = assertEquals;
|
export const deepStrictEqual = assertEquals;
|
||||||
export const notEqual = assertNotEquals;
|
export const notDeepStrictEqual = assertNotEquals;
|
||||||
export const strictEqual = assertStrictEquals;
|
export const strictEqual = assertStrictEquals;
|
||||||
|
export const notStrictEqual = assertNotStrictEquals;
|
||||||
export const match = assertMatch;
|
export const match = assertMatch;
|
||||||
export const throws = assertThrows;
|
export const throws = assertThrows;
|
||||||
|
|
65
std/node/assert_test.ts
Normal file
65
std/node/assert_test.ts
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
import {
|
||||||
|
assert as denoAssert,
|
||||||
|
assertEquals,
|
||||||
|
assertNotEquals,
|
||||||
|
assertStrictEquals,
|
||||||
|
assertNotStrictEquals,
|
||||||
|
assertMatch,
|
||||||
|
assertThrows,
|
||||||
|
fail as denoFail,
|
||||||
|
} from "../testing/asserts.ts";
|
||||||
|
|
||||||
|
import assert from "./assert.ts";
|
||||||
|
|
||||||
|
import {
|
||||||
|
ok,
|
||||||
|
assert as assert_,
|
||||||
|
deepStrictEqual,
|
||||||
|
notDeepStrictEqual,
|
||||||
|
strictEqual,
|
||||||
|
notStrictEqual,
|
||||||
|
match,
|
||||||
|
throws,
|
||||||
|
fail,
|
||||||
|
} from "./assert.ts";
|
||||||
|
|
||||||
|
Deno.test("API should be exposed", () => {
|
||||||
|
assertStrictEquals(
|
||||||
|
assert_,
|
||||||
|
assert,
|
||||||
|
"`assert()` should be the default export",
|
||||||
|
);
|
||||||
|
assertStrictEquals(assert_, denoAssert, "`assert()` should be exposed");
|
||||||
|
assertStrictEquals(assert_, ok, "`assert()` should be an alias of `ok()`");
|
||||||
|
assertStrictEquals(
|
||||||
|
assertEquals,
|
||||||
|
deepStrictEqual,
|
||||||
|
"`assertEquals()` should be exposed as `deepStrictEqual()`",
|
||||||
|
);
|
||||||
|
assertStrictEquals(
|
||||||
|
assertNotEquals,
|
||||||
|
notDeepStrictEqual,
|
||||||
|
"`assertNotEquals()` should be exposed as `notDeepStrictEqual()`",
|
||||||
|
);
|
||||||
|
assertStrictEquals(
|
||||||
|
assertStrictEquals,
|
||||||
|
strictEqual,
|
||||||
|
"`assertStrictEquals()` should be exposed as `strictEqual()`",
|
||||||
|
);
|
||||||
|
assertStrictEquals(
|
||||||
|
assertNotStrictEquals,
|
||||||
|
notStrictEqual,
|
||||||
|
"`assertNotStrictEquals()` should be exposed as `notStrictEqual()`",
|
||||||
|
);
|
||||||
|
assertStrictEquals(
|
||||||
|
assertMatch,
|
||||||
|
match,
|
||||||
|
"`assertMatch()` should be exposed as `match()`",
|
||||||
|
);
|
||||||
|
assertStrictEquals(
|
||||||
|
assertThrows,
|
||||||
|
throws,
|
||||||
|
"`assertThrows()` should be exposed as `throws()`",
|
||||||
|
);
|
||||||
|
assertStrictEquals(fail, denoFail, "`fail()` should be exposed");
|
||||||
|
});
|
|
@ -242,10 +242,20 @@ export function assertNotEquals(
|
||||||
* assertStrictEquals(1, 2)
|
* assertStrictEquals(1, 2)
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
export function assertStrictEquals(
|
||||||
|
actual: unknown,
|
||||||
|
expected: unknown,
|
||||||
|
msg?: string,
|
||||||
|
): void;
|
||||||
export function assertStrictEquals<T>(
|
export function assertStrictEquals<T>(
|
||||||
actual: T,
|
actual: T,
|
||||||
expected: T,
|
expected: T,
|
||||||
msg?: string,
|
msg?: string,
|
||||||
|
): void;
|
||||||
|
export function assertStrictEquals(
|
||||||
|
actual: unknown,
|
||||||
|
expected: unknown,
|
||||||
|
msg?: string,
|
||||||
): void {
|
): void {
|
||||||
if (actual === expected) {
|
if (actual === expected) {
|
||||||
return;
|
return;
|
||||||
|
@ -285,6 +295,37 @@ export function assertStrictEquals<T>(
|
||||||
throw new AssertionError(message);
|
throw new AssertionError(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make an assertion that `actual` and `expected` are not strictly equal.
|
||||||
|
* If the values are strictly equal then throw.
|
||||||
|
* ```ts
|
||||||
|
* assertNotStrictEquals(1, 1)
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export function assertNotStrictEquals(
|
||||||
|
actual: unknown,
|
||||||
|
expected: unknown,
|
||||||
|
msg?: string,
|
||||||
|
): void;
|
||||||
|
export function assertNotStrictEquals<T>(
|
||||||
|
actual: T,
|
||||||
|
expected: T,
|
||||||
|
msg?: string,
|
||||||
|
): void;
|
||||||
|
export function assertNotStrictEquals(
|
||||||
|
actual: unknown,
|
||||||
|
expected: unknown,
|
||||||
|
msg?: string,
|
||||||
|
): void {
|
||||||
|
if (actual !== expected) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new AssertionError(
|
||||||
|
msg ?? `Expected "actual" to be strictly unequal to: ${_format(actual)}\n`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make an assertion that actual contains expected. If not
|
* Make an assertion that actual contains expected. If not
|
||||||
* then thrown.
|
* then thrown.
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
assertMatch,
|
assertMatch,
|
||||||
assertEquals,
|
assertEquals,
|
||||||
assertStrictEquals,
|
assertStrictEquals,
|
||||||
|
assertNotStrictEquals,
|
||||||
assertThrows,
|
assertThrows,
|
||||||
assertThrowsAsync,
|
assertThrowsAsync,
|
||||||
AssertionError,
|
AssertionError,
|
||||||
|
@ -463,13 +464,42 @@ Deno.test({
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "assert* functions with specified type paratemeter",
|
name: "strictly unequal pass case",
|
||||||
|
fn(): void {
|
||||||
|
assertNotStrictEquals(true, false);
|
||||||
|
assertNotStrictEquals(10, 11);
|
||||||
|
assertNotStrictEquals("abc", "xyz");
|
||||||
|
assertNotStrictEquals(1, "1");
|
||||||
|
|
||||||
|
const xs = [1, false, "foo"];
|
||||||
|
const ys = [1, true, "bar"];
|
||||||
|
assertNotStrictEquals(xs, ys);
|
||||||
|
|
||||||
|
const x = { a: 1 };
|
||||||
|
const y = { a: 2 };
|
||||||
|
assertNotStrictEquals(x, y);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "strictly unequal fail case",
|
||||||
|
fn(): void {
|
||||||
|
assertThrows(
|
||||||
|
() => assertNotStrictEquals(1, 1),
|
||||||
|
AssertionError,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "assert* functions with specified type parameter",
|
||||||
fn(): void {
|
fn(): void {
|
||||||
assertEquals<string>("hello", "hello");
|
assertEquals<string>("hello", "hello");
|
||||||
assertNotEquals<number>(1, 2);
|
assertNotEquals<number>(1, 2);
|
||||||
assertArrayContains<boolean>([true, false], [true]);
|
assertArrayContains<boolean>([true, false], [true]);
|
||||||
const value = { x: 1 };
|
const value = { x: 1 };
|
||||||
assertStrictEquals<typeof value>(value, value);
|
assertStrictEquals<typeof value>(value, value);
|
||||||
|
assertNotStrictEquals<object>(value, { x: 1 });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue