-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathmulti-base.js
45 lines (39 loc) · 1.2 KB
/
multi-base.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as React from 'react'
import {render} 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)
})
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.',
)
})
// https://github.com/testing-library/eslint-plugin-testing-library/issues/188
/*
eslint
testing-library/prefer-screen-queries: "off",
*/