mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 07:43:35 +00:00
[PM-2132] Move all specs to the src directory (#5367)
This commit is contained in:
34
libs/common/spec/matchers/to-equal-buffer.ts
Normal file
34
libs/common/spec/matchers/to-equal-buffer.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 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.
|
||||
* This custom matcher will automatically instantiate a new Uint8Array on the received value
|
||||
* (and optionally, the expected value) and then call toEqual() on the resulting Uint8Arrays.
|
||||
*/
|
||||
export const toEqualBuffer: jest.CustomMatcher = function (
|
||||
received: ArrayBuffer,
|
||||
expected: Uint8Array | ArrayBuffer
|
||||
) {
|
||||
received = new Uint8Array(received);
|
||||
|
||||
if (expected instanceof ArrayBuffer) {
|
||||
expected = new Uint8Array(expected);
|
||||
}
|
||||
|
||||
if (this.equals(received, expected)) {
|
||||
return {
|
||||
message: () => `expected
|
||||
${received}
|
||||
not to match
|
||||
${expected}`,
|
||||
pass: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
message: () => `expected
|
||||
${received}
|
||||
to match
|
||||
${expected}`,
|
||||
pass: false,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user