( actual: T, expected: T, msg?: string, )
| 44 | * @param msg The optional message to display if the assertion fails. |
| 45 | */ |
| 46 | export function assertEquals<T>( |
| 47 | actual: T, |
| 48 | expected: T, |
| 49 | msg?: string, |
| 50 | ) { |
| 51 | if (equal(actual, expected)) { |
| 52 | return; |
| 53 | } |
| 54 | const msgSuffix = msg ? `: ${msg}` : "."; |
| 55 | let message = `Values are not equal${msgSuffix}`; |
| 56 | |
| 57 | const actualString = format(actual); |
| 58 | const expectedString = format(expected); |
| 59 | const stringDiff = (typeof actual === "string") && |
| 60 | (typeof expected === "string"); |
| 61 | const diffResult = stringDiff |
| 62 | ? diffStr(actual as string, expected as string) |
| 63 | : diff(actualString.split("\n"), expectedString.split("\n")); |
| 64 | const diffMsg = buildMessage(diffResult, { stringDiff }, arguments[3]) |
| 65 | .join("\n"); |
| 66 | message = `${message}\n${diffMsg}`; |
| 67 | throw new AssertionError(message); |
| 68 | } |
no test coverage detected