Skip to content

Noise in @std/expect's toMatchObject diff (vs. Jest's expect): object keys not present in the expected object #7077

@dandv

Description

@dandv

On failed expect(actual).toMatchObject(expected) assertions, Deno's differ dumps all keys in the actual object as - lines, making it very hard to spot the actual difference. Jest's differ includes only the keys specified in the expected object, and for extra array elements, it marks them with a +.

Steps to Reproduce

  1. Clone https://github.com/dandv/Deno-std-expect-toMatchObject-diff-noise.git
  2. Run deno task test

Expected behavior

Jest's expect failure output is scoped to the keys in expected:

error: Error: expect(received).toMatchObject(expected)

- Expected  - 0
+ Received  + 4

  Object {
    "author": Object {
      "name": "Ada Lovelace",
      "stats": Object {
        "posts": 42,
      },
    },
    "featured": true,
    "stats": Object {
      "likes": 812,
    },
    "tags": Array [
      "deno",
+     "typescript",
+     "javascript",
+     "runtime",
+     "tutorial",
    ],
    "title": "Getting Started with Deno",
  }

The four extra array elements are marked with + so the problem is easy to identify.


Deno's @std/expect dumps the entire actual object:

error: AssertionError: Values are not equal.


    [Diff] Actual / Expected


    {
-     allowComments: true,
      author: {
-       avatar: "https://example.dev/avatars/ada.png",
-       bio: "Pioneering developer and runtime enthusiast. Writes about compilers, runtimes, and elegant APIs.",
-       email: "[email protected]",
-       id: "u9876",
        name: "Ada Lovelace",
-       social: {
-         github: "ada-lovelace",
-         linkedin: "ada-lovelace-dev",
-         twitter: "@ada_codes",
-       },
        stats: {
-         followers: 1337,
-         following: 88,
          posts: 42,
        },
      },
-     body: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.",
-     category: {
-       description: "Server-side development and infrastructure topics.",
-       id: "cat-3",
-       name: "Backend",
-       slug: "backend",
-     },
      featured: true,
-     id: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
-     publishedAt: "2025-06-01T09:00:00Z",
-     readingTime: 7,
-     relatedArticles: [
-       {
-         id: "a0001",
-         slug: "deno-vs-node",
-         title: "Deno vs Node.js",
-       },
-       {
-         id: "a0002",
-         slug: "typescript-basics",
-         title: "TypeScript Basics",
-       },
-       {
-         id: "a0003",
-         slug: "modern-js-tooling",
-         title: "Modern JS Tooling",
-       },
-     ],
-     seo: {
-       canonicalUrl: "https://example.dev/blog/getting-started-with-deno",
-       metaDescription: "Learn the basics of Deno runtime in this hands-on guide.",
-       metaTitle: "Getting Started with Deno | Dev Blog",
-       openGraph: {
-         image: "https://example.dev/og/deno-guide.png",
-         type: "article",
-       },
-     },
-     slug: "getting-started-with-deno",
      stats: {
-       bookmarks: 309,
-       comments: 134,
        likes: 812,
-       shares: {
-         hackernews: 66,
-         linkedin: 87,
-         reddit: 153,
-         twitter: 204,
-       },
-       views: 29041,
      },
-     subtitle: "A practical guide to the modern JavaScript runtime",
      tags: [
        "deno",
-       "typescript",
-       "javascript",
-       "runtime",
-       "tutorial",
      ],
      title: "Getting Started with Deno",
-     updatedAt: "2025-06-12T16:45:00Z",
    }

Every property of the received object is dumped, including fields that were never mentioned in expected (e.g. seo, relatedArticles, body, category, slug, the full author.social block). All these appear as - removals, because the differ is comparing the full received value against the partial expected value.

The actual mismatch (tags) is buried near the bottom.

Environment

  • OS: Ubuntu 24.04
  • deno version: 2.7.11
  • std version: 1.0.18

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions