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

Multi-root node components aren't cleaned properly up after each test #295

Open
romansp opened this issue Feb 1, 2023 · 3 comments
Open
Labels
bug Something isn't working

Comments

@romansp
Copy link

romansp commented Feb 1, 2023

Describe the bug
Components that render multiple root nodes or <slot /> in root won't be cleaned up properly after each test or by calling cleanup manually.

To Reproduce
The following test cases will currently fail if added to auto-cleanup.js.

test('renders single slot component', () => {
  render({template: `<slot />`})

  expect(document.body.innerHTML).toMatchInlineSnapshot(`<div></div>`)
})

// this is about to fail because wrapping <div> from previous test won't be removed.
test('renders multiple root nodes component', () => {
  render({template: `
    <h1>Hello World</h1>
    <h2>Hello World</h2>`
  })

  expect(document.body.innerHTML).toMatchInlineSnapshot(`
    <div>
      <h1>Hello World</h1>
      <h2>Hello World</h2>
    </div>
  `)
})

// this will fail because body will still have 2 `<div>` elements attached.
test('cleans up after each test by default', () => {
  expect(document.body.innerHTML).toMatchInlineSnapshot(``)
})

Expected behavior

cleanup should remove all attached wrapping elements from body.

Related information:

  • @testing-library/vue version: 6.6.1
  • Vue version: 3.2.45
  • node version: 18.2.1
  • npm (or yarn) version: yarn 3.2.4
@romansp romansp added the bug Something isn't working label Feb 1, 2023
@XavierChevalier
Copy link

I have the same issue actually. Any news about this?

@pathai-scasarotto
Copy link

I think I am also seeing something similar. I was in the process of upgrading a number of dependencies.

@adamdehaven
Copy link

I've tried calling cleanup manually along with component.unmount (for @testing-library/vue) and the previous instance is still in the DOM when the test runs

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

No branches or pull requests

4 participants