( a: Record<string, any>, b: Record<string, any>, options?: DiffOptions, )
| 135 | } |
| 136 | |
| 137 | function compareObjects( |
| 138 | a: Record<string, any>, |
| 139 | b: Record<string, any>, |
| 140 | options?: DiffOptions, |
| 141 | ) { |
| 142 | let difference; |
| 143 | let hasThrown = false; |
| 144 | |
| 145 | try { |
| 146 | const formatOptions = getFormatOptions(FORMAT_OPTIONS, options); |
| 147 | difference = getObjectsDifference(a, b, formatOptions, options); |
| 148 | } catch { |
| 149 | hasThrown = true; |
| 150 | } |
| 151 | |
| 152 | const noDiffMessage = getCommonMessage(NO_DIFF_MESSAGE, options); |
| 153 | // If the comparison yields no results, compare again but this time |
| 154 | // without calling `toJSON`. It's also possible that toJSON might throw. |
| 155 | if (difference === undefined || difference === noDiffMessage) { |
| 156 | const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options); |
| 157 | difference = getObjectsDifference(a, b, formatOptions, options); |
| 158 | |
| 159 | if (difference !== noDiffMessage && !hasThrown) { |
| 160 | difference = `${getCommonMessage( |
| 161 | SIMILAR_MESSAGE, |
| 162 | options, |
| 163 | )}\n\n${difference}`; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | return difference; |
| 168 | } |
| 169 | |
| 170 | function getFormatOptions( |
| 171 | formatOptions: PrettyFormatOptions, |
no test coverage detected