MCPcopy Create free account
hub / github.com/dethcrypto/TypeChain / typedAssert

Function typedAssert

packages/test-utils/src/test.ts:10–34  ·  view source on GitHub ↗
(actual: T, expected: T)

Source from the content-addressed store, hash-verified

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 */
10export 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
36export function isBigNumber(v: any): boolean {
37 return v.constructor.name === 'BigNumber' || v.constructor.name === 'BN'

Callers 15

Overload.test.tsFile · 0.90
Events.test.tsFile · 0.90
Payable.test.tsFile · 0.90
Overload.test.tsFile · 0.90
Events.test.tsFile · 0.90

Calls 4

isBigNumberFunction · 0.85
isBigNumberArrayFunction · 0.85
isBigNumberObjectFunction · 0.85
toStringMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…