Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toMatchObject doesn't support matchers but only exact values #6111

Closed
NaveenNeti opened this issue Oct 12, 2024 · 3 comments
Closed

toMatchObject doesn't support matchers but only exact values #6111

NaveenNeti opened this issue Oct 12, 2024 · 3 comments
Labels
bug Something isn't working expect

Comments

@NaveenNeti
Copy link

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 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
@kt3k kt3k added bug Something isn't working expect labels Oct 28, 2024
@eryue0220
Copy link
Contributor

I'll check this later.

@NaveenNeti
Copy link
Author

Thank you @eryue0220 I will test this tomorrow 🙏

@NaveenNeti
Copy link
Author

Confirmed this is fixed @eryue0220 Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working expect
Projects
None yet
Development

No branches or pull requests

3 participants