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.06k stars 110 forks source link

after manually calling the umount method, cleanupAtWrapper will report an error #311

Closed hcg1023 closed 3 months ago

hcg1023 commented 4 months ago

Describe the bug A clear and concise description of what the bug is.

After manually calling the umount method, cleanupAtWrapper will report an error TypeError: Cannot read properties of null (reading 'parentNode')

To Reproduce Steps to reproduce the behavior:

cleanup should not report an error

Expected behavior

Screenshots

image

Related information:

Relevant code or config (if any)

import { createDragDropManager, DragDropManager } from 'dnd-core'
import { render, cleanup } from '@testing-library/vue'
import { useDndContextInjector } from '../DndContext'
import DndProvider from '../DndProvider'
import { TestBackend } from 'react-dnd-test-backend'
import { defineComponent, h } from 'vue-demi'
import { describe, afterEach, it, expect } from 'vitest'

describe('DndProvider', () => {
  afterEach(cleanup)

  it('stores DragDropManager in global context and cleans up on unmount', () => {
    let capturedManager

    const ChildComponent = defineComponent(() => {
      capturedManager = useDndContextInjector()
      return () => null
    })
    const TestProvider = defineComponent(() => {
      return () =>
        h(
          DndProvider,
          { backend: TestBackend },
          { default: () => h(ChildComponent) }
        )
    })

    const mountProvider = () => render(TestProvider)

    const globalInstance = (): DragDropManager =>
      (global as any)[Symbol.for('__VUE_DND_CONTEXT_INSTANCE__')] as any

    // Single mount & unmount works
    const root = mountProvider()
    expect(globalInstance()).toEqual(capturedManager)
    root.unmount()
    expect(globalInstance()).toEqual(null)

    // Two mounted components do a refcount
    const rootA = mountProvider()
    const rootB = mountProvider()
    expect(globalInstance()).toEqual(capturedManager)
    rootA.unmount()
    expect(globalInstance()).toEqual(capturedManager)
    rootB.unmount()
    expect(globalInstance()).toEqual(null)
  })
})

Additional context

github-actions[bot] commented 3 months ago

:tada: This issue has been resolved in version 8.0.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket: