-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add ".toEqualBytes()" assertion
- Loading branch information
1 parent
59d438e
commit 96b09c8
Showing
6 changed files
with
47 additions
and
26 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 was deleted.
Oops, something went wrong.
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
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,39 @@ | ||
import { invariant } from 'outvariant' | ||
|
||
expect.extend({ | ||
toEqualBytes(expected: unknown, actual: unknown) { | ||
invariant(isUint8Array(expected), '') | ||
invariant(isUint8Array(actual), '') | ||
|
||
if (expected.length !== actual.length) { | ||
return { | ||
pass: false, | ||
message: () => | ||
`Expected Uint8Array of length (${expected.length}) but got (${actual.length})`, | ||
actual: actual.length, | ||
expected: expected.length, | ||
} | ||
} | ||
|
||
for (let i = 0; i < expected.length; i++) { | ||
if (actual[i] !== expected[i]) { | ||
return { | ||
pass: false, | ||
message: () => | ||
`Expected Uint8Array to be equal but found a difference at index ${i}`, | ||
actual: actual[i], | ||
expected: expected[i], | ||
} | ||
} | ||
} | ||
|
||
return { | ||
pass: true, | ||
message: () => '...', | ||
} | ||
}, | ||
}) | ||
|
||
function isUint8Array(value: unknown): value is Uint8Array { | ||
return value?.constructor.name === 'Uint8Array' | ||
} |