(
actual: T,
expected: T,
options: EqualErrorMessageOptions = {},
)
| 25 | } |
| 26 | |
| 27 | export function buildEqualErrorMessage<T>( |
| 28 | actual: T, |
| 29 | expected: T, |
| 30 | options: EqualErrorMessageOptions = {}, |
| 31 | ): string { |
| 32 | const { formatter = format, msg, summary = "Values are not equal." } = |
| 33 | options; |
| 34 | const msgPrefix = msg ? `${msg}: ` : ""; |
| 35 | const actualString = formatter(actual); |
| 36 | const expectedString = formatter(expected); |
| 37 | |
| 38 | let message = `${msgPrefix}${summary}`; |
| 39 | |
| 40 | const stringDiff = isString(actual) && isString(expected); |
| 41 | const diffResult = stringDiff |
| 42 | ? diffStr(actual, expected) |
| 43 | : diff(actualString.split("\n"), expectedString.split("\n")); |
| 44 | const diffMsg = buildMessage(diffResult, { stringDiff }).join("\n"); |
| 45 | message = `${message}\n${diffMsg}`; |
| 46 | |
| 47 | return message; |
| 48 | } |
| 49 | |
| 50 | export function buildNotEqualErrorMessage<T>( |
| 51 | actual: T, |
no test coverage detected