( actual: unknown, expected: T, msg?: string, )
| 30 | * @param msg The optional message to display if the assertion fails. |
| 31 | */ |
| 32 | export 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 | } |
no test coverage detected