forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpinnerSpec.tsx
52 lines (45 loc) · 1.7 KB
/
SpinnerSpec.tsx
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
import { describe, expect, it } from 'vitest';
import { render, screen } from '@testing-library/react';
import Spinner from '../src/Spinner';
describe('<Spinner>', () => {
it('Should render a basic spinner correctly', () => {
render(<Spinner data-testid="test" animation="border" />);
expect(screen.getByTestId('test').classList).toContain('spinner-border');
});
it('Should render a spinner with a custom element, variant and size ', () => {
render(
<Spinner
data-testid="test"
as="span"
animation="grow"
variant="primary"
size="sm"
/>,
);
const spinnerElem = screen.getByTestId('test');
expect(spinnerElem.tagName).toEqual('SPAN');
expect(spinnerElem.classList).toContain('spinner-grow');
expect(spinnerElem.classList).toContain('spinner-grow-sm');
expect(spinnerElem.classList).toContain('text-primary');
});
it('Should render a spinner with other properties', () => {
render(<Spinner data-testid="test" animation="grow" role="status" />);
const spinnerElem = screen.getByTestId('test');
expect(spinnerElem.classList).toContain('spinner-grow');
expect(spinnerElem.getAttribute('role')!).toEqual('status');
});
it('Should render child elements', () => {
render(
<Spinner data-testid="test" animation="grow">
<span id="testChild" />
</Spinner>,
);
const spinnerElem = screen.getByTestId('test');
expect(spinnerElem.children.length).toEqual(1);
});
it('Should have div as default component', () => {
render(<Spinner data-testid="test" animation="border" />);
const spinnerElem = screen.getByTestId('test');
expect(spinnerElem.tagName).toEqual('DIV');
});
});