after manually calling the umount method, cleanupAtWrapper will report an error
bug
<!-- Thanks for your interest in the project. We appreciate bugs filed and PRs submitted! -->
<!--
- For questions related to using the library, please join the Discord server (https://discord.gg/testing-library) instead of filing an issue on GitHub.
- Please fill out this template with all the relevant information so we can
understand what's going on and fix the issue.
- If you're issue is regarding one of the query APIs (`getByText`,
`getByLabelText`, etc), then please file it on the `@testing-library/dom`
repository instead. Thanks :)
--->
**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
<!-- Please try to provide a working demo using Codesandbox, a GitHub repo or similar! -->
**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
**Screenshots**
<img width="921" alt="image" src="https://github.com/testing-library/vue-testing-library/assets/47942469/b2b24324-bdbc-4f29-8a38-fe1670988cea">
<!-- If applicable, add screenshots to help explain your problem. -->
**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)
```javascript
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**
<!-- Add any other context about the problem here. -->
关闭于 2024-03-18 1 条评论