Skip to content

Commit df6b8b8

Browse files
committed
Item/test: refine custom Matcher
1 parent 0dbb918 commit df6b8b8

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/App/Item/index.test.tsx

+8-9
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ test('should each todo object value is set to Item element', () => {
4646
})
4747

4848
test('should correct render default class state', () => {
49-
const { container } = render(
49+
const { getByTestId } = render(
5050
<Provider store={initialStore}>
5151
<App />
5252
</Provider>
5353
)
5454

5555
// when not.completed & not.onEdit, SwitchStyle doesn't show .completed .editting selectors
56-
expect(container.querySelector('[class*="completed"]')).toBe(null)
57-
expect(container.querySelector('[class*="editing"]')).toBe(null)
56+
expect(getByTestId('todo-item')).not.toHaveClass('completed')
57+
expect(getByTestId('todo-item')).not.toHaveClass('editing')
5858
})
5959

6060
test('should work "check" complete toggle button', () => {
61-
const { getByTestId, container } = render(
61+
const { getByTestId } = render(
6262
<Provider store={initialStore}>
6363
<App />
6464
</Provider>
@@ -69,18 +69,18 @@ test('should work "check" complete toggle button', () => {
6969
expect(
7070
(getByTestId('todo-item-complete-check') as HTMLInputElement).checked
7171
).toBe(true)
72-
expect(container.querySelector('[class*="completed"]')).toBeInTheDocument()
72+
expect(getByTestId('todo-item')).toHaveClass('completed')
7373

7474
// should working as toggle
7575
fireEvent.click(getByTestId('todo-item-complete-check'))
7676
expect(
7777
(getByTestId('todo-item-complete-check') as HTMLInputElement).checked
7878
).toBe(false)
79-
expect(container.querySelector('[class*="completed"]')).toBe(null)
79+
expect(getByTestId('todo-item')).not.toHaveClass('completed')
8080
})
8181

8282
test('should work edit mode toggle', () => {
83-
const { getByTestId, container } = render(
83+
const { getByTestId } = render(
8484
<Provider store={initialStore}>
8585
<App />
8686
</Provider>
@@ -90,9 +90,8 @@ test('should work edit mode toggle', () => {
9090
expect(getByTestId('todo-edit-input')).not.toBeVisible()
9191

9292
// double click todo text label, then enable todo text edit code
93-
9493
fireEvent.doubleClick(getByTestId('todo-body-text'))
95-
expect(container.querySelector('[class*="editing"]')).toBeInTheDocument()
94+
expect(getByTestId('todo-item')).toHaveClass('editing')
9695
// @TODO in jsdom, dynamic .editing classCSSSelector doesn't apply. So tipically show/hide UI test are difficult.
9796
// @ref https://spectrum.chat/testing-library/general/testing-an-accordion~b004a9b1-b104-4eb1-a73b-43c60b1a3630?m=MTU1NDQ4NDIzMTQ5Ng==
9897
//expect(getByTestId('todo-edit-input')).toBeVisible()

0 commit comments

Comments
 (0)