deno.land / std@0.224.0 / assert / assert_strict_equals_test.ts

assert_strict_equals_test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { AssertionError, assertStrictEquals, assertThrows } from "./mod.ts";
Deno.test({ name: "strict types test", fn() { 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() { assertStrictEquals(true, true); assertStrictEquals(10, 10); assertStrictEquals("abc", "abc"); assertStrictEquals(NaN, NaN);
const xs = [1, false, "foo"]; const ys = xs; assertStrictEquals(xs, ys);
const x = { a: 1 }; const y = x; assertStrictEquals(x, y); },});
Deno.test({ name: "strict failed with structure diff", fn() { assertThrows( () => assertStrictEquals({ a: 1, b: 2 }, { a: 1, c: [3] }), AssertionError, ` { a: 1,+ c: [+ 3,+ ],- b: 2, }`, ); },});
Deno.test({ name: "strict failed with reference diff", fn() { assertThrows( () => assertStrictEquals({ a: 1, b: 2 }, { a: 1, b: 2 }), AssertionError, `Values have the same structure but are not reference-equal.
{ a: 1, b: 2, }`, ); },});
Deno.test({ name: "strict failed with custom msg", fn() { assertThrows( () => assertStrictEquals({ a: 1 }, { a: 1 }, "CUSTOM MESSAGE"), AssertionError, `Values have the same structure but are not reference-equal: CUSTOM MESSAGE
{ a: 1, }`, ); },});
std

Version Info

Tagged at
3 weeks ago