mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
feat(testing/asserts): use assertion signature for "assertStrictEquals" (#1984)
This commit is contained in:
parent
54ddd4a6a3
commit
4e8f0e7bb8
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user