feat(testing/asserts): use assertion signature for "assertStrictEquals" (#1984)

This commit is contained in:
Jesse Jackson 2022-03-03 23:31:19 -06:00 committed by GitHub
parent 54ddd4a6a3
commit 4e8f0e7bb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 18 deletions

View File

@ -45,12 +45,15 @@ Deno.test("[async] debounce: flushed", function () {
Deno.test("[async] debounce: with params & context", async function () {
const params: Array<string | number> = [];
const d = debounce(function (param1: string, param2: number) {
assertEquals(d.pending, false);
params.push(param1);
params.push(param2);
assertStrictEquals(d, this);
}, 100);
const d: DebouncedFunction<[string, number]> = debounce(
function (param1: string, param2: number) {
assertEquals(d.pending, false);
params.push(param1);
params.push(param2);
assertStrictEquals(d, this);
},
100,
);
// @ts-expect-error Argument of type 'number' is not assignable to parameter of type 'string'.
d(1, 1);
d("foo", 1);

View File

@ -323,21 +323,11 @@ export function assertNotEquals(
* assertStrictEquals(1, 2)
* ```
*/
export function assertStrictEquals(
actual: unknown,
expected: unknown,
msg?: string,
): void;
export function assertStrictEquals<T>(
actual: T,
actual: unknown,
expected: T,
msg?: string,
): void;
export function assertStrictEquals(
actual: unknown,
expected: unknown,
msg?: string,
): void {
): asserts actual is T {
if (actual === expected) {
return;
}

View File

@ -874,6 +874,30 @@ Deno.test({
},
});
Deno.test({
name: "strict types test",
fn(): void {
const x = { number: 2 };
const y = x as Record<never, never>;
const z = x as unknown;
// y.number;
// ~~~~~~
// Property 'number' does not exist on type 'Record<never, never>'.deno-ts(2339)
assertStrictEquals(y, x);
y.number; // ok
// z.number;
// ~
// Object is of type 'unknown'.deno-ts(2571)
assertStrictEquals(z, x);
z.number; // ok
},
});
Deno.test({
name: "strict pass case",
fn(): void {