-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cleanup): automatically cleanup if afterEach is detected
You can disable this with the RTL_SKIP_CLEANUP environment variable if you so choose, but it's recommended to have cleanup work this way. Closes #428
- Loading branch information
Kent C. Dodds
committed
Aug 9, 2019
1 parent
2f17920
commit 6862dd1
Showing
4 changed files
with
41 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react' | ||
|
||
let render | ||
beforeAll(() => { | ||
process.env.RTL_SKIP_CLEANUP = 'true' | ||
const rtl = require('../') | ||
render = rtl.render | ||
}) | ||
|
||
// This one verifies that if RTL_SKIP_CLEANUP is set | ||
// that we DON'T auto-wire up the afterEach for folks | ||
test('first', () => { | ||
render(<div>hi</div>) | ||
}) | ||
|
||
test('second', () => { | ||
expect(document.body.innerHTML).toEqual('<div><div>hi</div></div>') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react' | ||
import {render} from '../' | ||
|
||
// This just verifies that by importing RTL in an | ||
// environment which supports afterEach (like jest) | ||
// we'll get automatic cleanup between tests. | ||
test('first', () => { | ||
render(<div>hi</div>) | ||
}) | ||
|
||
test('second', () => { | ||
expect(document.body.innerHTML).toEqual('') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
import '@testing-library/jest-dom/extend-expect' | ||
|
||
afterEach(() => { | ||
// have to do a dynamic import so we don't mess up jest mocking for old-act.js | ||
require('../src').cleanup() | ||
}) |