mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
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:
parent
ce9795ab61
commit
772c4f982a
@ -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,
|
||||
);
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user