MCPcopy Create free account
hub / github.com/denoland/std / assertStrictEquals

Function assertStrictEquals

assert/strict_equals.ts:32–68  ·  view source on GitHub ↗
(
  actual: unknown,
  expected: T,
  msg?: string,
)

Source from the content-addressed store, hash-verified

30 * @param msg The optional message to display if the assertion fails.
31 */
32export function assertStrictEquals<T>(
33 actual: unknown,
34 expected: T,
35 msg?: string,
36): asserts actual is T {
37 if (Object.is(actual, expected)) {
38 return;
39 }
40
41 const msgSuffix = msg ? `: ${msg}` : ".";
42 let message: string;
43
44 const actualString = format(actual);
45 const expectedString = format(expected);
46
47 if (actualString === expectedString) {
48 const withOffset = actualString
49 .split("\n")
50 .map((l) => ` ${l}`)
51 .join("\n");
52 message =
53 `Values have the same structure but are not reference-equal${msgSuffix}\n\n${
54 red(withOffset)
55 }\n`;
56 } else {
57 const stringDiff = (typeof actual === "string") &&
58 (typeof expected === "string");
59 const diffResult = stringDiff
60 ? diffStr(actual as string, expected as string)
61 : diff(actualString.split("\n"), expectedString.split("\n"));
62 const diffMsg = buildMessage(diffResult, { stringDiff }, arguments[3])
63 .join("\n");
64 message = `Values are not strictly equal${msgSuffix}\n${diffMsg}`;
65 }
66
67 throw new AssertionError(message);
68}

Callers 15

fnFunction · 0.90
min_by_test.tsFile · 0.90
deep_merge_test.tsFile · 0.90
max_by_test.tsFile · 0.90
debounce_test.tsFile · 0.90
lazy_test.tsFile · 0.90
assertRejectsReasonFunction · 0.90
all_keyed_test.tsFile · 0.90
test.tsFile · 0.90
copy_test.tsFile · 0.90

Calls 5

formatFunction · 0.90
redFunction · 0.90
diffFunction · 0.90
diffStrFunction · 0.85
buildMessageFunction · 0.85

Tested by

no test coverage detected