-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathhidden-message.test.js
31 lines (25 loc) · 1.01 KB
/
hidden-message.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
import 'jest-dom/extend-expect';
import 'react-testing-library/cleanup-after-each';
import React from 'react';
import {render, fireEvent} from 'react-testing-library';
import {HiddenMessage} from '../src/hidden-message';
// we don't want to have to wait for a full second (as defined by Fade's
// timeout) in order to test our component, so we mock out CSSTransition so that
// we can either show or hide content immediately
jest.mock('react-transition-group', () => ({
CSSTransition: props => (props.in ? props.children : ''),
}));
describe('HiddenMessage', () => {
test('shows hidden message when toggled', () => {
const children = 'foo';
const {getByText, queryByText} = render(
<HiddenMessage>{children}</HiddenMessage>
);
const button = getByText(/toggle/i);
expect(queryByText(children)).not.toBeInTheDocument();
fireEvent.click(button);
expect(getByText(children)).toBeInTheDocument();
fireEvent.click(button);
expect(queryByText(children)).not.toBeInTheDocument();
});
});