pokerogue/test/test-utils/matchers/to-equal-array-unsorted.ts
Bertie690 5ed9e152ab
[Test] Port over + augment remaining test matchers from pkty (#6159)
* Partially ported over pkty matchers (WIP)

* Cleaned up some more matchers

* Fiexd up matchers

* Fixed up remaining matchers

* Removed the word "matcher" from the pkty matcher functions

If we want them back we can always undo this commit and convert the other custom ones

* Added wip spite test

* Added `toHaveUsedPP` matcher

* Fixed up docs and tests

* Fixed spite test

* Ran biome

* Apply Biome

* Reverted biome breaking i18next

* Update src/typings/i18next.d.ts comment

* Fixed log message to not be overly verbose

* Added option to check for all PP used in pp matcher + cleaned up grudge tests

* Fixed up tests

* Fixed tests and such

* Fix various TSDocs + missing TSDoc imports
2025-08-02 15:35:06 -07:00

48 lines
1.6 KiB
TypeScript

import { getOnelineDiffStr } from "#test/test-utils/string-utils";
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
/**
* Matcher that checks if an array contains exactly the given items, disregarding order.
* @param received - The received value. Should be an array of elements
* @param expected - The array to check equality with
* @returns Whether the matcher passed
*/
export function toEqualArrayUnsorted(
this: MatcherState,
received: unknown,
expected: unknown[],
): SyncExpectationResult {
if (!Array.isArray(received)) {
return {
pass: false,
message: () => `Expected an array, but got ${this.utils.stringify(received)}!`,
};
}
if (received.length !== expected.length) {
return {
pass: false,
message: () => `Expected to receive array of length ${received.length}, but got ${expected.length} instead!`,
actual: received,
expected,
};
}
const actualSorted = received.slice().sort();
const expectedSorted = expected.slice().sort();
const pass = this.equals(actualSorted, expectedSorted, [...this.customTesters, this.utils.iterableEquality]);
const actualStr = getOnelineDiffStr.call(this, actualSorted);
const expectedStr = getOnelineDiffStr.call(this, expectedSorted);
return {
pass,
message: () =>
pass
? `Expected ${actualStr} to NOT exactly equal ${expectedStr} without order, but it did!`
: `Expected ${actualStr} to exactly equal ${expectedStr} without order, but it didn't!`,
expected: expectedSorted,
actual: actualSorted,
};
}