-
Notifications
You must be signed in to change notification settings - Fork 82
/
modal.test.js
32 lines (25 loc) · 912 Bytes
/
modal.test.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
import 'jest-dom/extend-expect';
import 'react-testing-library/cleanup-after-each';
import React from 'react';
import {render, within} from 'react-testing-library';
import {Modal} from '../src/Modal';
describe('Modal', () => {
test('-> renders children', () => {
const {debug, getByText} = render(
<Modal>
<div className="hey">test text</div>
</Modal>
);
// we can see that the modal is appended to body
debug();
// this query is scoped to the full document
expect(getByText(/test text/)).toBeInTheDocument();
// we can scope our queries to only what is rendered in the React portal
// using react-testing-library's within, passing it
const {getByText: getByTextWithin} = within(
document.getElementById('modal-root')
);
// this query is scoped to #modal-root
expect(getByTextWithin(/test text/)).toBeInTheDocument();
});
});