2022-07-26 03:40:32 +02:00
|
|
|
/**
|
|
|
|
* The inbuilt toEqual() matcher will always return TRUE when provided with 2 ArrayBuffers.
|
|
|
|
* This is because an ArrayBuffer must be wrapped in a new Uint8Array to be accessible.
|
2023-04-26 12:16:07 +02:00
|
|
|
* This custom matcher will automatically instantiate a new Uint8Array on the received value
|
2022-07-26 03:40:32 +02:00
|
|
|
* (and optionally, the expected value) and then call toEqual() on the resulting Uint8Arrays.
|
|
|
|
*/
|
|
|
|
export const toEqualBuffer: jest.CustomMatcher = function (
|
2023-08-04 04:13:33 +02:00
|
|
|
received: ArrayBuffer | Uint8Array,
|
2023-11-29 22:15:20 +01:00
|
|
|
expected: ArrayBuffer | Uint8Array,
|
2022-07-26 03:40:32 +02:00
|
|
|
) {
|
|
|
|
received = new Uint8Array(received);
|
2023-08-04 04:13:33 +02:00
|
|
|
expected = new Uint8Array(expected);
|
2022-07-26 03:40:32 +02:00
|
|
|
|
|
|
|
if (this.equals(received, expected)) {
|
|
|
|
return {
|
|
|
|
message: () => `expected
|
|
|
|
${received}
|
|
|
|
not to match
|
|
|
|
${expected}`,
|
|
|
|
pass: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
message: () => `expected
|
|
|
|
${received}
|
|
|
|
to match
|
|
|
|
${expected}`,
|
|
|
|
pass: false,
|
|
|
|
};
|
|
|
|
};
|