deno_std
deno_std copied to clipboard
toMatchObject doesn't support matchers but only exact values
Thank you to all for the work on this project.
The JSR page for @std/expect states "Jest compatible expect assertion functions"
While trying to use toMatchObject I noticed it doesn't seem to support asymmetric matchers similar to what jest would allow.
e.g. within Jest
expect({ position: { x: 0, y: 0 } }).toMatchObject({
position: {
x: expect.any(Number),
y: expect.any(Number)
}
});
Running the same test in Deno:
Deno.test("CustomMatcher tests", () => {
expect({ position: { x: 0, y: 0 } }).toMatchObject({
position: {
x: expect.any(Number),
y: expect.any(Number),
},
});
});
Results in the output:
error: AssertionError: Values are not equal.
[Diff] Actual / Expected
{
position: {
+ x: {
+ value: [Function: Number],
+ },
+ y: {
+ value: [Function: Number],
+ },
- x: 0,
- y: 0,
},
}
Describe the solution you'd like
- Would be great if the
toMatchObjectwould have consistent behavior with jest and allow for asymmetric matchers - From what I can see it would require edits to: https://jsr.io/@std/expect/1.0.5/_matchers.ts#L461 https://jsr.io/@std/expect/1.0.5/_matchers.ts#L487
Would be keen to help provide an MR to add support for it assuming the project owners see value.
Versions
deno: 2.0.0
@std/assert/1.0.6