1
0
mirror of https://github.com/bitwarden/directory-connector synced 2025-12-05 23:53:21 +00:00
Files
directory-connector/jslib/common/spec/matchers/to-equal-buffer.ts
Addison Beck eacdb6b8a8 [AC-1743] pt. 2: Update eslintrc and fix any errors (#393)
* Sync eslintrc with clients repo

* Autofix one eslint error

* Add type attributes to buttons for eslint

* Properly destroy ApiKeyComponent

* Fix eslint issues related to state

* Fix eslint warnings for default named imports

* Ran prettier

* Be more proactive about an unsubscribe

* Rework subscription
2024-01-05 11:36:19 +10:00

32 lines
847 B
TypeScript

/**
* 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 | Uint8Array,
expected: ArrayBuffer | Uint8Array
) {
received = new Uint8Array(received);
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,
};
};