( expected: Array<unknown>, received: Array<unknown>, expand: boolean, )
| 219 | const indentation = 'Received'.replaceAll(/\w/g, ' '); |
| 220 | |
| 221 | const printDiffCall = ( |
| 222 | expected: Array<unknown>, |
| 223 | received: Array<unknown>, |
| 224 | expand: boolean, |
| 225 | ) => |
| 226 | received |
| 227 | .map((arg, i) => { |
| 228 | if (i < expected.length) { |
| 229 | if (isEqualValue(expected[i], arg)) { |
| 230 | return `${indentation} ${printCommon(arg)},`; |
| 231 | } |
| 232 | |
| 233 | if (isLineDiffableArg(expected[i], arg)) { |
| 234 | const difference = diff(expected[i], arg, {expand}); |
| 235 | |
| 236 | if ( |
| 237 | typeof difference === 'string' && |
| 238 | difference.includes('- Expected') && |
| 239 | difference.includes('+ Received') |
| 240 | ) { |
| 241 | // Display diff with indentation. |
| 242 | // Omit annotation in case multiple args have diff. |
| 243 | return `${difference |
| 244 | .split('\n') |
| 245 | .slice(3) |
| 246 | .map(line => indentation + line) |
| 247 | .join('\n')},`; |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | // Display + only if received arg has no corresponding expected arg. |
| 253 | return `${ |
| 254 | indentation + |
| 255 | (i < expected.length |
| 256 | ? ` ${printReceived(arg)}` |
| 257 | : RECEIVED_COLOR(`+ ${stringify(arg)}`)) |
| 258 | },`; |
| 259 | }) |
| 260 | .join('\n'); |
| 261 | |
| 262 | const isLineDiffableCall = ( |
| 263 | expected: Array<unknown>, |
no test coverage detected