Skip to content

Commit 1f416fe

Browse files
committed
test(drawer): Remove nesting breaking tests
1 parent f4cf9a3 commit 1f416fe

File tree

1 file changed

+33
-38
lines changed

1 file changed

+33
-38
lines changed

packages/react-component-library/src/components/Drawer/Drawer.test.tsx

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import React from 'react'
22
import { renderToStaticMarkup } from 'react-dom/server'
33
import '@testing-library/jest-dom/extend-expect'
4-
import {
5-
render,
6-
RenderResult,
7-
fireEvent,
8-
cleanup,
9-
} from '@testing-library/react'
4+
import { render, RenderResult, fireEvent } from '@testing-library/react'
105

116
import { Drawer } from '.'
127

@@ -33,45 +28,45 @@ describe('Drawer', () => {
3328
renderToStaticMarkup(children)
3429
)
3530
})
31+
})
3632

37-
describe('and the `isOpen` attribute and `onClose` callback are provided', () => {
38-
beforeEach(() => {
39-
cleanup()
40-
onCloseSpy = jest.fn()
33+
describe('and the `isOpen` attribute and `onClose` callback are provided', () => {
34+
beforeEach(() => {
35+
children = <h1>Arbitrary JSX</h1>
36+
onCloseSpy = jest.fn()
4137

42-
wrapper = render(
43-
<Drawer isOpen onClose={onCloseSpy}>
44-
{children}
45-
</Drawer>
46-
)
47-
})
38+
wrapper = render(
39+
<Drawer isOpen onClose={onCloseSpy}>
40+
{children}
41+
</Drawer>
42+
)
43+
})
4844

49-
it('applies the `is-open` class', () => {
50-
expect(wrapper.getByTestId('drawer-wrapper').classList).toContain(
51-
'is-open'
45+
it('applies the `is-open` class', () => {
46+
expect(wrapper.getByTestId('drawer-wrapper').classList).toContain(
47+
'is-open'
48+
)
49+
})
50+
51+
describe('and a user clicks on the close button', () => {
52+
beforeEach(() => {
53+
fireEvent(
54+
wrapper.getByTestId('drawer-close'),
55+
new MouseEvent('click', {
56+
bubbles: true,
57+
cancelable: true,
58+
})
5259
)
5360
})
5461

55-
describe('and a user clicks on the close button', () => {
56-
beforeEach(() => {
57-
fireEvent(
58-
wrapper.getByTestId('drawer-close'),
59-
new MouseEvent('click', {
60-
bubbles: true,
61-
cancelable: true,
62-
})
63-
)
64-
})
65-
66-
it('invokes the `onClose` callback', () => {
67-
expect(onCloseSpy).toHaveBeenCalled()
68-
})
62+
it('invokes the `onClose` callback', () => {
63+
expect(onCloseSpy).toHaveBeenCalled()
64+
})
6965

70-
it('removes the `is-open` class', () => {
71-
expect(wrapper.getByTestId('drawer-wrapper').classList).not.toContain(
72-
'is-open'
73-
)
74-
})
66+
it('removes the `is-open` class', () => {
67+
expect(wrapper.getByTestId('drawer-wrapper').classList).not.toContain(
68+
'is-open'
69+
)
7570
})
7671
})
7772
})

0 commit comments

Comments
 (0)