1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 13:23:34 +00:00
Files
browser/libs/common/spec/matchers/to-contain-partial-objects.ts
Thomas Rittson 8c13ea894b [PM-16917] Remove jest-extended dependency (#12798)
* add toContainPartialObjects matcher (replacing toIncludeAllPartialMembers from jest-extended)
* replace jest-extended matchers with equivalent default matchers
2025-01-15 10:43:26 -05:00

32 lines
728 B
TypeScript

import { EOL } from "os";
import { diff } from "jest-diff";
export const toContainPartialObjects: jest.CustomMatcher = function (
received: Array<any>,
expected: Array<any>,
) {
const matched = this.equals(
received,
expect.arrayContaining(expected.map((e) => expect.objectContaining(e))),
);
if (matched) {
return {
message: () =>
"Expected the received array NOT to include partial matches for all expected objects." +
EOL +
diff(expected, received),
pass: true,
};
}
return {
message: () =>
"Expected the received array to contain partial matches for all expected objects." +
EOL +
diff(expected, received),
pass: false,
};
};