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

Bad diff output on DOM objects #6939

Open
6 tasks done
tuhm1 opened this issue Nov 20, 2024 · 0 comments
Open
6 tasks done

Bad diff output on DOM objects #6939

tuhm1 opened this issue Nov 20, 2024 · 0 comments

Comments

@tuhm1
Copy link

tuhm1 commented Nov 20, 2024

Describe the bug

The diff function doesn't work on DOM objects because they have a special output format.

AssertionError: expected <div><img></img></div> to match object { tagName: 'DIV', id: 'root', …(2) }

- Expected
+ Received

- Object {
-   "children": Object {
-     "0": Object {
-       "src": "http://url.com/",
-       "tagName": "IMG",
-     },
-     "1": Object {
-       "tagName": "BUTTON",
-       "textContent": "Go",
-     },
-     "length": 2,
-   },
-   "className": "d-flex",
-   "id": "root",
-   "tagName": "DIV",
- }
+ <div>
+   <img />
+ </div>

Ideally, I think only differing property values should be shown.

Reproduction

const node = document.createElement("div");
node.append(document.createElement("img"));

expect(node).toMatchObject({
  tagName: "DIV",
  id: "root",
  className: "d-flex",
  children: {
    length: 2,
    [0]: { tagName: "IMG", src: "http://url.com/" },
    [1]: { tagName: "BUTTON", textContent: "Go" },
  },
});

StackBlitz

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vitest/ui: latest => 2.1.5 
    vite: latest => 5.4.11 
    vitest: latest => 2.1.5

Used Package Manager

npm

Validations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant