Skip to content

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

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

Closed
hcg1023 opened this issue Feb 28, 2024 · 1 comment · Fixed by #312
Closed

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

hcg1023 opened this issue Feb 28, 2024 · 1 comment · Fixed by #312
Labels
bug Something isn't working released

Comments

@hcg1023
Copy link
Contributor

hcg1023 commented Feb 28, 2024

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:

  • @testing-library/vue version: 8.0.2
  • Vue version: 3.2.33
  • node version: 16
  • npm (or yarn) version: pnpm v8

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

@hcg1023 hcg1023 added the bug Something isn't working label Feb 28, 2024
hcg1023 added a commit to hcg1023/vue-testing-library that referenced this issue Feb 28, 2024
hcg1023 added a commit to hcg1023/vue-testing-library that referenced this issue Feb 28, 2024
hcg1023 added a commit to hcg1023/vue-testing-library that referenced this issue Mar 7, 2024
hcg1023 added a commit to hcg1023/vue-testing-library that referenced this issue Mar 7, 2024
afontcu pushed a commit that referenced this issue Mar 18, 2024
* fix: check wrapper element to fix #311
Copy link

🎉 This issue has been resolved in version 8.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

1 participant