1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 02:03:39 +00:00
Files
browser/libs/common/spec/matchers/to-contain-partial-objects.ts

30 lines
703 B
TypeScript

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." +
"\n" +
diff(expected, received),
pass: true,
};
}
return {
message: () =>
"Expected the received array to contain partial matches for all expected objects." +
"\n" +
diff(expected, received),
pass: false,
};
};