Skip to content

Automatic unmount of rendered components at end of each test #234

Closed
@aleclarson

Description

@aleclarson

Describe the Feature

I'm testing hooks that modify the global state of a library, so they need to be unmounted before the next test begins. Currently, I'm using this workaround:

import { render as renderImpl, RenderAPI } from 'react-native-testing-library'

const rendered: RenderAPI[] = []
const render: typeof renderImpl = (...args) => {
  const elem = renderImpl(...args)
  rendered.push(elem)
  return elem
}

beforeEach(() => {
  rendered.forEach(elem => elem.unmount())
  rendered.length = 0
})

Ideally, react-native-testing-library would export a function that lets developers opt-in to this behavior, like the following:

import { setAutoUnmount } from 'react-native-testing-library'

setAutoUnmount(true)

Then I wouldn't need to maintain this code myself. :)

Possible Implementations

See the workaround.

Related Issues

None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions