( error: AssertionErrorWithStack, options: DiffOptions, )
| 131 | }; |
| 132 | |
| 133 | function assertionErrorMessage( |
| 134 | error: AssertionErrorWithStack, |
| 135 | options: DiffOptions, |
| 136 | ) { |
| 137 | const {expected, actual, generatedMessage, message, operator, stack} = error; |
| 138 | const diffString = diff(expected, actual, options); |
| 139 | const hasCustomMessage = !generatedMessage; |
| 140 | const operatorName = getOperatorName(operator, stack); |
| 141 | const trimmedStack = stack |
| 142 | .replace(message, '') |
| 143 | .replaceAll(/AssertionError(.*)/g, ''); |
| 144 | |
| 145 | if (operatorName === 'doesNotThrow') { |
| 146 | return ( |
| 147 | // eslint-disable-next-line prefer-template |
| 148 | buildHintString(assertThrowingMatcherHint(operatorName)) + |
| 149 | chalk.reset('Expected the function not to throw an error.\n') + |
| 150 | chalk.reset('Instead, it threw:\n') + |
| 151 | ` ${printReceived(actual)}` + |
| 152 | chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') + |
| 153 | trimmedStack |
| 154 | ); |
| 155 | } |
| 156 | |
| 157 | if (operatorName === 'throws') { |
| 158 | if (error.generatedMessage) { |
| 159 | return ( |
| 160 | buildHintString(assertThrowingMatcherHint(operatorName)) + |
| 161 | chalk.reset(error.message) + |
| 162 | chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') + |
| 163 | trimmedStack |
| 164 | ); |
| 165 | } |
| 166 | return ( |
| 167 | buildHintString(assertThrowingMatcherHint(operatorName)) + |
| 168 | chalk.reset('Expected the function to throw an error.\n') + |
| 169 | chalk.reset("But it didn't throw anything.") + |
| 170 | chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') + |
| 171 | trimmedStack |
| 172 | ); |
| 173 | } |
| 174 | |
| 175 | if (operatorName === 'fail') { |
| 176 | return ( |
| 177 | buildHintString(assertMatcherHint(operator, operatorName, expected)) + |
| 178 | chalk.reset(hasCustomMessage ? `Message:\n ${message}` : '') + |
| 179 | trimmedStack |
| 180 | ); |
| 181 | } |
| 182 | |
| 183 | return ( |
| 184 | // eslint-disable-next-line prefer-template |
| 185 | buildHintString(assertMatcherHint(operator, operatorName, expected)) + |
| 186 | chalk.reset(`Expected value ${operatorMessage(operator)}`) + |
| 187 | ` ${printExpected(expected)}\n` + |
| 188 | chalk.reset('Received:\n') + |
| 189 | ` ${printReceived(actual)}` + |
| 190 | chalk.reset(hasCustomMessage ? `\n\nMessage:\n ${message}` : '') + |
no test coverage detected