Skip to content

Commit 4626ba1

Browse files
committed
Run cleanup() when test runner supports teardown()
1 parent d43e278 commit 4626ba1

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import {cleanup} from './pure'
22

33
// if we're running in a test runner that supports afterEach
4-
// then we'll automatically run cleanup afterEach test
4+
// or teardown then we'll automatically run cleanup afterEach test
55
// this ensures that tests run in isolation from each other
66
// if you don't like this then either import the `pure` module
77
// or set the RTL_SKIP_AUTO_CLEANUP env variable to 'true'.
8-
if (typeof afterEach === 'function' && !process.env.RTL_SKIP_AUTO_CLEANUP) {
9-
afterEach(async () => {
10-
await cleanup()
11-
})
8+
if (!process.env.RTL_SKIP_AUTO_CLEANUP) {
9+
if (typeof afterEach === 'function') {
10+
afterEach(async () => {
11+
await cleanup()
12+
})
13+
} else if (typeof teardown === 'function') {
14+
teardown(async () => {
15+
await cleanup()
16+
})
17+
}
1218
}
1319

1420
export * from './pure'

0 commit comments

Comments
 (0)