fix(expect): fix the function signature of toMatchObject() (#4202)

* fix(expect): fix the function signature of `toMatchObject`

* chore: format code
This commit is contained in:
BlackGlory 2024-01-16 06:09:30 +08:00 committed by GitHub
parent ce9795ab61
commit 772c4f982a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View File

@ -432,7 +432,7 @@ export function toMatch(
export function toMatchObject(
context: MatcherContext,
expected: Record<PropertyKey, unknown>,
expected: Record<PropertyKey, unknown> | Record<PropertyKey, unknown>[],
): MatchResult {
if (context.isNot) {
let objectMatch = false;
@ -440,7 +440,7 @@ export function toMatchObject(
assertObjectMatch(
// deno-lint-ignore no-explicit-any
context.value as Record<PropertyKey, any>,
expected,
expected as Record<PropertyKey, unknown>,
context.customMessage,
);
objectMatch = true;
@ -459,7 +459,7 @@ export function toMatchObject(
assertObjectMatch(
// deno-lint-ignore no-explicit-any
context.value as Record<PropertyKey, any>,
expected,
expected as Record<PropertyKey, unknown>,
context.customMessage,
);
}

View File

@ -31,14 +31,22 @@ Deno.test("expect().toMatchObject()", () => {
};
expect(house0).toMatchObject(desiredHouse);
expect([house0]).toMatchObject([desiredHouse]);
expect(house1).not.toMatchObject(desiredHouse);
expect([house1]).not.toMatchObject([desiredHouse]);
assertThrows(() => {
expect(house1).toMatchObject(desiredHouse);
}, AssertionError);
assertThrows(() => {
expect([house1]).toMatchObject([desiredHouse]);
}, AssertionError);
assertThrows(() => {
expect(house0).not.toMatchObject(desiredHouse);
}, AssertionError);
assertThrows(() => {
expect([house0]).not.toMatchObject([desiredHouse]);
}, AssertionError);
});

View File

@ -74,7 +74,11 @@ export interface Expected {
toHaveReturnedWith(expected: unknown): void;
toHaveReturned(): void;
toMatch(expected: RegExp): void;
toMatchObject(expected: Record<PropertyKey, unknown>): void;
toMatchObject(
expected:
| Record<PropertyKey, unknown>
| Record<PropertyKey, unknown>[],
): void;
toReturn(): void;
toReturnTimes(expected: number): void;
toReturnWith(expected: unknown): void;