testing-library / vue-testing-library

🦎 Simple and complete Vue.js testing utilities that encourage good testing practices.
http://testing-library.com/vue
MIT License
1.08k stars 110 forks source link

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

Open romansp opened 1 year ago

romansp commented 1 year ago

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:

XavierChevalier commented 1 year ago

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

pathai-scasarotto commented 9 months ago

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

adamdehaven commented 3 months ago

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