mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-12-15 14:25:32 +01:00
* Added rudimentary test matchers for `toEqualArrayUnsorted` and `toHaveTypes` Might port the rest at a later date * Actually run the effing setup matchers file + fixed ls lint to not be angy * added dev dep * Update .ls-lint.yml * Update .ls-lint.yml --------- Co-authored-by: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com> Co-authored-by: Amani H. <109637146+xsn34kzx@users.noreply.github.com>
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
|
|
|
/**
|
|
* Matcher to check if an array contains exactly the given items, disregarding order.
|
|
* @param received - The object to check. Should be an array of elements.
|
|
* @returns The result of the matching
|
|
*/
|
|
export function toEqualArrayUnsorted(this: MatcherState, received: unknown, expected: unknown): SyncExpectationResult {
|
|
if (!Array.isArray(received)) {
|
|
return {
|
|
pass: this.isNot,
|
|
message: () => `Expected an array, but got ${this.utils.stringify(received)}!`,
|
|
};
|
|
}
|
|
|
|
if (!Array.isArray(expected)) {
|
|
return {
|
|
pass: this.isNot,
|
|
message: () => `Expected to recieve an array, but got ${this.utils.stringify(expected)}!`,
|
|
};
|
|
}
|
|
|
|
if (received.length !== expected.length) {
|
|
return {
|
|
pass: this.isNot,
|
|
message: () => `Expected to recieve array of length ${received.length}, but got ${expected.length}!`,
|
|
actual: received,
|
|
expected,
|
|
};
|
|
}
|
|
|
|
const gotSorted = received.slice().sort();
|
|
const wantSorted = expected.slice().sort();
|
|
const pass = this.equals(gotSorted, wantSorted, [...this.customTesters, this.utils.iterableEquality]);
|
|
|
|
return {
|
|
pass: this.isNot !== pass,
|
|
message: () =>
|
|
`Expected ${this.utils.stringify(received)} to exactly equal ${this.utils.stringify(expected)} without order!`,
|
|
actual: gotSorted,
|
|
expected: wantSorted,
|
|
};
|
|
}
|