-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepeat.test.tsx
More file actions
38 lines (34 loc) · 1.3 KB
/
Repeat.test.tsx
File metadata and controls
38 lines (34 loc) · 1.3 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
31
32
33
34
35
36
37
38
import { render, screen } from '@testing-library/react'
import Repeat from './Repeat'
describe('Repeat.tsx', () => {
it('should render without any errors or crash', () => {
render(
<Repeat times={1}>
<div>this is going to repeated</div>
</Repeat>
)
})
it('should render nothing without any errors if <times> prop is not provided', () => {
render(
<Repeat>
<div data-testid='children'>this is content</div>
</Repeat>
)
expect(screen.queryByTestId('children')).not.toBeInTheDocument()
})
it('should render children repeated n times', () => {
render(
<Repeat times={3}>
<div data-testid='children'>this is content</div>
</Repeat>
)
expect(screen.queryAllByTestId('children').length).toBe(3)
})
it('should render children of function type repeated n times', () => {
render(<Repeat times={3}>{(idx) => <div data-testid={`children-${idx}`}>this is content-{idx}</div>}</Repeat>)
expect(screen.queryAllByTestId(/^children-(.*)$/).length).toBe(3)
expect(screen.queryByTestId('children-0')).toBeInTheDocument()
expect(screen.queryByTestId('children-1')).toBeInTheDocument()
expect(screen.queryByTestId('children-2')).toBeInTheDocument()
})
})