-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpress-server.test.jsx
45 lines (32 loc) · 1.12 KB
/
express-server.test.jsx
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 React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import '@testing-library/jest-dom';
import expressServer from './express-server';
import App from './src/App';
import randomGibberish from './random-gibberish';
let expressServerInstance;
let user;
beforeAll(async () => {
expressServerInstance = await expressServer();
user = userEvent.setup();
});
afterAll(() => {
expressServerInstance.close();
});
it('can save and load a color', async () => {
render(<App />);
const colorInput = screen.getByLabelText('color');
expect(colorInput).toBeInTheDocument();
const colorName = `chartreuse ${randomGibberish()}`;
await user.click(colorInput);
await user.type(colorInput, colorName);
const saveButton = screen.getByText('save');
expect(saveButton).toBeInTheDocument();
await user.click(saveButton);
const loadButton = screen.getByText('load');
expect(loadButton).toBeInTheDocument();
await user.click(loadButton);
const color = await screen.findByText(`color ${colorName}`);
expect(color).toBeInTheDocument();
});