-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoopOption.test.jsx
More file actions
30 lines (25 loc) · 1.12 KB
/
ScoopOption.test.jsx
File metadata and controls
30 lines (25 loc) · 1.12 KB
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
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import ScoopOption from '../ScoopOption';
test.only('indicate if scoop count is non-int or out of range', async () => {
render(<ScoopOption name="" imagePath="" updateItemCount={jest.fn()} />);
// expect input to be invalid with negative number
const vanillaInput = screen.getByRole('spinbutton');
userEvent.clear(vanillaInput);
userEvent.type(vanillaInput, '-1');
expect(vanillaInput).toHaveClass('is-invalid');
// replace with decimal input
userEvent.clear(vanillaInput);
userEvent.type(vanillaInput, '2.5');
expect(vanillaInput).toHaveClass('is-invalid');
// replace with input that's too high
userEvent.clear(vanillaInput);
userEvent.type(vanillaInput, '11');
expect(vanillaInput).toHaveClass('is-invalid');
// replace with valid input
// note: here we're testing our validation rules (namely that the input can display as valid)
// and not react-bootstrap's response
userEvent.clear(vanillaInput);
userEvent.type(vanillaInput, '3');
expect(vanillaInput).not.toHaveClass('is-invalid');
});