-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathApp.test.js
77 lines (54 loc) · 2.07 KB
/
App.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* @jest-environment jsdom
*/
import React from 'react';
import renderer from 'react-test-renderer';
import { act } from 'react-test-renderer';
import App from './App';
import Checkbox from './src/components/checkbox';
import { screen } from '@testing-library/dom';
import {fireEvent, render} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
jest.useFakeTimers();
describe('<App />', () => {
it('has 1 child', async () => {
const tree = renderer.create(<App />).toJSON();
await act(async () => {
expect(tree.children.length).toBe(1);
})
});
it('renders correctly', async () => {
const tree = renderer.create(<App />).toJSON();
await act(async () => {
expect(tree).toMatchSnapshot();
})
});
test('Signup flow', async () => {
const app = render(<App />);
userEvent.click(app.getByText("Sign up", { exact: false }))
userEvent.type(app.getByPlaceholderText("Your Email"), '[email protected]' )
userEvent.type(app.getByPlaceholderText("Your Password"), 'password123' )
await act(async () => {
userEvent.click(app.getByText("Signup", { exact: false }))
await act(async () => {
expect(app).toMatchSnapshot();
})
})
// userEvent.click(screen.getByText("Signup"))
// // expect(screen).toContain("You have not saved any Achievements yet!");
// expect(screen.getByText("You have not saved any Achievements yet!")).toBeTruthy();
});
});
describe('<Checkbox />', () => {
test('Checkbox is created with appropriate text', () => {
const update = jest.fn();
const checkbox = render(<Checkbox label="Work" saveSelected={update} />);
expect(checkbox.queryByText("Work")).toBeTruthy();
});
test('Checkbox calls supplied function on click', () => {
const update = jest.fn();
const checkbox = render(<Checkbox label="Work" saveSelected={update} />);
fireEvent.click(checkbox.getByText("Work"));
expect(update).toHaveBeenCalled();
});
});