-
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.
fix: Specify baseElement without container (#394)
* Add expected behavior of base element * Fix expected behavior of baseElement * Improve tests
- Loading branch information
Showing
3 changed files
with
45 additions
and
4 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,41 @@ | ||
import React from 'react' | ||
import {render, cleanup} from '../' | ||
|
||
// these are created once per test suite and reused for each case | ||
let treeA, treeB | ||
beforeAll(() => { | ||
treeA = document.createElement('div') | ||
treeB = document.createElement('div') | ||
document.body.appendChild(treeA) | ||
document.body.appendChild(treeB) | ||
}) | ||
|
||
afterAll(() => { | ||
treeA.parentNode.removeChild(treeA) | ||
treeB.parentNode.removeChild(treeB) | ||
}) | ||
|
||
afterEach(cleanup) | ||
|
||
test('baseElement isolates trees from one another', () => { | ||
const {getByText: getByTextInA} = render(<div>Jekyll</div>, { | ||
baseElement: treeA, | ||
}) | ||
const {getByText: getByTextInB} = render(<div>Hyde</div>, { | ||
baseElement: treeB, | ||
}) | ||
|
||
expect(() => getByTextInA('Jekyll')).not.toThrow( | ||
'Unable to find an element with the text: Jekyll.', | ||
) | ||
expect(() => getByTextInB('Jekyll')).toThrow( | ||
'Unable to find an element with the text: Jekyll.', | ||
) | ||
|
||
expect(() => getByTextInA('Hyde')).toThrow( | ||
'Unable to find an element with the text: Hyde.', | ||
) | ||
expect(() => getByTextInB('Hyde')).not.toThrow( | ||
'Unable to find an element with the text: Hyde.', | ||
) | ||
}) |
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