Skip to content

Commit 05f3835

Browse files
committed
tests: update tests
1 parent f5f3c98 commit 05f3835

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

packages/coreui-react/src/components/collapse/__tests__/CCollapse.spec.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ test('CCollapse customize', async () => {
1515
})
1616

1717
test('CCollapse use case test', async () => {
18-
jest.useFakeTimers()
1918
const { rerender } = render(<CCollapse visible={false}>Test</CCollapse>)
2019
expect(screen.getByText('Test')).toHaveClass('collapse')
2120
expect(screen.getByText('Test')).not.toHaveClass('show')
@@ -24,15 +23,15 @@ test('CCollapse use case test', async () => {
2423
expect(screen.getByText('Test')).not.toHaveClass('collapse')
2524
expect(screen.getByText('Test')).not.toHaveClass('show')
2625
expect(screen.getByText('Test')).toHaveClass('collapsing')
27-
jest.runAllTimers()
26+
await new Promise((r) => setTimeout(r, 1000))
2827
expect(screen.getByText('Test')).toHaveClass('collapse')
2928
expect(screen.getByText('Test')).toHaveClass('show')
3029
expect(screen.getByText('Test')).not.toHaveClass('collapsing')
3130
rerender(<CCollapse visible={false}>Test</CCollapse>)
3231
expect(screen.getByText('Test')).not.toHaveClass('collapse')
3332
expect(screen.getByText('Test')).not.toHaveClass('show')
3433
expect(screen.getByText('Test')).toHaveClass('collapsing')
35-
jest.runAllTimers()
34+
await new Promise((r) => setTimeout(r, 1000))
3635
expect(screen.getByText('Test')).toHaveClass('collapse')
3736
expect(screen.getByText('Test')).not.toHaveClass('show')
3837
expect(screen.getByText('Test')).not.toHaveClass('collapsing')

packages/coreui-react/src/components/dropdown/__tests__/CDropdown.spec.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ test('CDropdown change visible prop', async () => {
5454
})
5555

5656
test('CDropdown click', async () => {
57-
jest.useFakeTimers()
5857
render(
5958
<CDropdown>
6059
<CDropdownToggle>Test</CDropdownToggle>
@@ -71,10 +70,9 @@ test('CDropdown click', async () => {
7170
}
7271
jest.runAllTimers()
7372
expect(screen.getByText('Test').closest('div')).toHaveClass('show')
74-
fireEvent.click(document) //click outside
73+
fireEvent.mouseUp(document.body) //click outside
74+
await new Promise((r) => setTimeout(r, 1000))
7575
expect(screen.getByText('Test').closest('div')).not.toHaveClass('show')
76-
jest.runAllTimers()
77-
jest.useRealTimers()
7876
})
7977

8078
test('CDropdown example', async () => {

packages/coreui-react/src/components/form/__tests__/CFormRange.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test('CFormRange customize', async () => {
2727
expect(container.firstChild).toHaveAttribute('max', '150')
2828
expect(container.firstChild).toHaveAttribute('min', '20')
2929
expect(container.firstChild).toHaveAttribute('readonly', '')
30-
expect(container.firstChild).toHaveAttribute('steps', '2')
30+
expect(container.firstChild).toHaveAttribute('step', '2')
3131
expect(container.firstChild).toHaveAttribute('type', 'range')
3232
expect(container.firstChild).toHaveAttribute('value', '80')
3333
})

packages/coreui-react/src/components/offcanvas/__tests__/COffcanvas.spec.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test('COffcanvas customize one', async () => {
2929
})
3030

3131
test('COffcanvas customize and event on click backdrop', async () => {
32-
jest.useFakeTimers()
32+
// jest.useFakeTimers()
3333
const onHide = jest.fn()
3434
const { container } = render(
3535
<COffcanvas
@@ -56,11 +56,13 @@ test('COffcanvas customize and event on click backdrop', async () => {
5656
fireEvent.click(backdrop)
5757
}
5858
expect(onHide).toHaveBeenCalledTimes(1)
59+
expect(container.firstChild).toHaveClass('show')
60+
expect(container.firstChild).toHaveClass('hiding')
61+
await new Promise((r) => setTimeout(r, 1000))
5962
expect(container.firstChild).not.toHaveClass('show')
6063
})
6164

6265
test('COffcanvas customize and event on keypress', async () => {
63-
jest.useFakeTimers()
6466
const onHide = jest.fn()
6567
const { container } = render(
6668
<COffcanvas
@@ -93,5 +95,8 @@ test('COffcanvas customize and event on keypress', async () => {
9395
})
9496
}
9597
expect(onHide).toHaveBeenCalledTimes(1)
98+
expect(container.firstChild).toHaveClass('show')
99+
expect(container.firstChild).toHaveClass('hiding')
100+
await new Promise((r) => setTimeout(r, 1000))
96101
expect(container.firstChild).not.toHaveClass('show')
97102
})

packages/coreui-react/src/components/tabs/__tests__/CTabPane.spec.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ test('CTabPane customize', async () => {
1818
})
1919

2020
test('CTabContent use case test', async () => {
21-
jest.useFakeTimers()
2221
const { rerender } = render(
2322
<CTabContent>
2423
<CTabPane visible={false}>Test</CTabPane>
@@ -33,7 +32,7 @@ test('CTabContent use case test', async () => {
3332
)
3433
expect(screen.getByText('Test')).not.toHaveClass('show')
3534
expect(screen.getByText('Test')).toHaveClass('active')
36-
jest.runAllTimers()
35+
await new Promise((r) => setTimeout(r, 1000))
3736
expect(screen.getByText('Test')).toHaveClass('show')
3837
expect(screen.getByText('Test')).toHaveClass('active')
3938
rerender(
@@ -43,9 +42,7 @@ test('CTabContent use case test', async () => {
4342
)
4443
expect(screen.getByText('Test')).not.toHaveClass('show')
4544
expect(screen.getByText('Test')).not.toHaveClass('active')
46-
jest.runAllTimers()
45+
await new Promise((r) => setTimeout(r, 1000))
4746
expect(screen.getByText('Test')).not.toHaveClass('show')
4847
expect(screen.getByText('Test')).not.toHaveClass('active')
49-
jest.runAllTimers()
50-
jest.useRealTimers()
5148
})

packages/coreui-react/src/components/toast/__tests__/CToast.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test('CToast customize', async () => {
3232
})
3333

3434
test('CToast click on dismiss button', async () => {
35-
jest.useFakeTimers()
35+
// jest.useFakeTimers()
3636
const onClose = jest.fn()
3737
const { container } = render(
3838
<CToast
@@ -71,6 +71,7 @@ test('CToast click on dismiss button', async () => {
7171
fireEvent.click(btn)
7272
}
7373
jest.runAllTimers()
74+
await new Promise((r) => setTimeout(r, 1000))
7475
expect(onClose).toHaveBeenCalledTimes(1)
7576
expect(container.firstChild).toBeNull()
7677
jest.useRealTimers()

packages/coreui-react/src/components/toast/__tests__/__snapshots__/CToast.spec.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ exports[`CToast customize 5`] = `
5757
<div
5858
aria-atomic="true"
5959
aria-live="assertive"
60-
class="toast fade bg-warning border-0 bazinga show"
60+
class="toast fade bg-warning border-0 bazinga showing"
6161
role="alert"
6262
>
6363
Test

0 commit comments

Comments
 (0)