Skip to content

Commit 90b5a8c

Browse files
committed
Improve demo clarity
1 parent b98df9b commit 90b5a8c

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

tests/__tests__/form.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ test('Review form submits', async () => {
1111
const fakeReview = {
1212
title: 'An Awesome Movie',
1313
review: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
14-
rating: '3',
15-
recommend: true
14+
rating: '3'
1615
}
1716

1817
const {
@@ -46,7 +45,7 @@ test('Review form submits', async () => {
4645
expect(ratingSelect.checked).toBe(true)
4746
expect(initiallySelectedInput.checked).toBe(false)
4847

49-
// Get the Input element by its implicit ARIA role.
48+
// Get the Input element by its implicit ARIA role
5049
const recommendInput = getByRole('checkbox')
5150

5251
expect(recommendInput.checked).toBe(false)
@@ -56,13 +55,13 @@ test('Review form submits', async () => {
5655
// NOTE: in jsdom, it's not possible to trigger a form submission
5756
// by clicking on the submit button. This is really unfortunate.
5857
// So the next best thing is to fireEvent a submit on the form itself
59-
// then ensure that there's a submit button.
58+
// then ensure that there's a submit button
6059
expect(submitButton).toBeEnabled()
6160
expect(submitButton).toHaveAttribute('type', 'submit')
6261

6362
await fireEvent.click(submitButton)
6463

65-
// Assert event has been emitted.
66-
expect(emitted().submit).toHaveLength(1)
67-
expect(emitted().submit[0]).toEqual([fakeReview])
64+
// Assert event has been emitted
65+
expect(emitted()).toHaveProperty('submit')
66+
expect(emitted().submit[0][0]).toMatchObject(fakeReview)
6867
})

tests/__tests__/simple-button.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ test('renders button with text', () => {
1212
props: { text }
1313
})
1414

15-
expect(getByRole('button')).toHaveTextContent(text)
15+
// Get the only element with a 'button' role
16+
const button = getByRole('button')
17+
18+
expect(button).toHaveTextContent(text)
1619
})
1720

1821
test('click event is emitted when button is clicked', async () => {
@@ -22,8 +25,10 @@ test('click event is emitted when button is clicked', async () => {
2225
props: { text }
2326
})
2427

25-
// Send a click event to the element with a 'button' role
28+
// Send a click event
2629
await fireEvent.click(getByRole('button'))
2730

28-
expect(emitted().click).toHaveLength(1)
31+
// Expect that the event emitted a "click" event. We should test for emitted
32+
// events has they are part of the public API of the component.
33+
expect(emitted()).toHaveProperty('click')
2934
})

0 commit comments

Comments
 (0)