-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: custom machers + event custom macher
- Loading branch information
Showing
5 changed files
with
53 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// @ts-nocheck | ||
|
||
declare global { | ||
namespace jest { | ||
interface Matchers<R> { | ||
toMatchEventStructure(expected: any): R; | ||
} | ||
} | ||
} | ||
|
||
const customMatchers = { | ||
toMatchEventStructure(received: any, expected: any): any { | ||
const { block_hash, block_number, transaction_hash, ...eventData } = received; | ||
|
||
// Check if required properties exist | ||
const hasRequiredProps = block_hash && block_number && transaction_hash; | ||
|
||
// Check if event data matches | ||
const eventDataMatches = this.equals(eventData, expected); | ||
|
||
return { | ||
actual: received, | ||
pass: hasRequiredProps && eventDataMatches, | ||
message: () => | ||
`Expected event to match structure with dynamic properties.\n\n` + | ||
`Expected: ${this.utils.printExpected(expected)}\n` + | ||
`Received: ${this.utils.printReceived(eventData)}`, | ||
}; | ||
}, | ||
}; | ||
|
||
export default customMatchers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters