(actual: T, expected: T)
| 8 | * It has some special handling for BigNumber :SHRUG: The reason for this is that I wanted to avoid creating specific functions for bignumbers which would force for me to export BigNumber in types (instead of just having it as generic type) WHICH is always PITA. |
| 9 | */ |
| 10 | export function typedAssert<T>(actual: T, expected: T): void { |
| 11 | if (isBigNumber(actual) && isBigNumber(expected)) { |
| 12 | expect((actual as any).toString()).toEqual((expected as any).toString()) |
| 13 | return |
| 14 | } |
| 15 | |
| 16 | if (isBigNumberArray(actual) && isBigNumberArray(expected)) { |
| 17 | expect(actual.map((a) => a.toString())).toEqual(expected.map((a) => a.toString())) |
| 18 | return |
| 19 | } |
| 20 | |
| 21 | if (isBigNumberObject(actual) && isBigNumberObject(expected)) { |
| 22 | const actualFiltered = omitBy(actual as any, (v, k) => k.startsWith('__')) |
| 23 | expect(mapValues(actualFiltered as any, (a) => a.toString())).toEqual( |
| 24 | mapValues(expected as any, (a) => a.toString()), |
| 25 | ) |
| 26 | return |
| 27 | } |
| 28 | |
| 29 | if (typeof expected === 'object') { |
| 30 | expect(actual as any).toBeAnObjectWith(expected as any) |
| 31 | } else { |
| 32 | expect(actual as any).toEqual(expected as any) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | export function isBigNumber(v: any): boolean { |
| 37 | return v.constructor.name === 'BigNumber' || v.constructor.name === 'BN' |
no test coverage detected
searching dependent graphs…