Skip to content

Commit 2efd1d2

Browse files
committed
Fix small bug with code examples in part5c
1 parent 71182e4 commit 2efd1d2

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/content/5/en/part5c.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -691,19 +691,20 @@ If an <i>label</i> were defined for the input field, the input field could be lo
691691
The test could locate the input field as follows:
692692

693693
```js
694-
test('<NoteForm /> updates parent state and calls onSubmit', () => {
694+
test('<NoteForm /> updates parent state and calls onSubmit', async () => {
695+
const user = userEvent.setup()
695696
const createNote = vi.fn()
696697

697698
render(<NoteForm createNote={createNote} />)
698699

699700
const input = screen.getByLabelText('content') // highlight-line
700701
const sendButton = screen.getByText('save')
701702

702-
userEvent.type(input, 'testing a form...' )
703-
userEvent.click(sendButton)
703+
await user.type(input, 'testing a form...')
704+
await user.click(sendButton)
704705

705706
expect(createNote.mock.calls).toHaveLength(1)
706-
expect(createNote.mock.calls[0][0].content).toBe('testing a form...' )
707+
expect(createNote.mock.calls[0][0].content).toBe('testing a form...')
707708
})
708709
```
709710

@@ -737,16 +738,17 @@ const NoteForm = ({ createNote }) => {
737738
Now finding the right input field is easy with the method [getByPlaceholderText](https://testing-library.com/docs/queries/byplaceholdertext):
738739

739740
```js
740-
test('<NoteForm /> updates parent state and calls onSubmit', () => {
741+
test('<NoteForm /> updates parent state and calls onSubmit', async () => {
742+
const user = userEvent.setup()
741743
const createNote = vi.fn()
742744

743745
render(<NoteForm createNote={createNote} />)
744746

745747
const input = screen.getByPlaceholderText('write note content here') // highlight-line
746748
const sendButton = screen.getByText('save')
747749

748-
userEvent.type(input, 'testing a form...')
749-
userEvent.click(sendButton)
750+
await user.type(input, 'testing a form...')
751+
await user.click(sendButton)
750752

751753
expect(createNote.mock.calls).toHaveLength(1)
752754
expect(createNote.mock.calls[0][0].content).toBe('testing a form...')

src/content/5/fi/osa5c.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -689,19 +689,20 @@ Jos syötekentälle olisi määritelty <i>label</i>, voisi kyseisen syötekentä
689689
Testi löytäisi syötekentän seuraavasti:
690690

691691
```js
692-
test('<NoteForm /> updates parent state and calls onSubmit', () => {
692+
test('<NoteForm /> updates parent state and calls onSubmit', async () => {
693+
const user = userEvent.setup()
693694
const createNote = vi.fn()
694695

695696
render(<NoteForm createNote={createNote} />)
696697

697698
const input = screen.getByLabelText('content') // highlight-line
698699
const sendButton = screen.getByText('save')
699700

700-
userEvent.type(input, 'testing a form...' )
701-
userEvent.click(sendButton)
701+
await user.type(input, 'testing a form...')
702+
await user.click(sendButton)
702703

703704
expect(createNote.mock.calls).toHaveLength(1)
704-
expect(createNote.mock.calls[0][0].content).toBe('testing a form...' )
705+
expect(createNote.mock.calls[0][0].content).toBe('testing a form...')
705706
})
706707
```
707708

@@ -735,19 +736,20 @@ const NoteForm = ({ createNote }) => {
735736
Nyt oikean syötekentän etsiminen onnistuu metodin [getByPlaceholderText](https://testing-library.com/docs/queries/byplaceholdertext) avulla:
736737

737738
```js
738-
test('<NoteForm /> updates parent state and calls onSubmit', () => {
739+
test('<NoteForm /> updates parent state and calls onSubmit', async () => {
740+
const user = userEvent.setup()
739741
const createNote = vi.fn()
740742

741743
render(<NoteForm createNote={createNote} />)
742744

743745
const input = screen.getByPlaceholderText('write note content here') // highlight-line
744746
const sendButton = screen.getByText('save')
745747

746-
userEvent.type(input, 'testing a form...' )
747-
userEvent.click(sendButton)
748+
await user.type(input, 'testing a form...')
749+
await user.click(sendButton)
748750

749751
expect(createNote.mock.calls).toHaveLength(1)
750-
expect(createNote.mock.calls[0][0].content).toBe('testing a form...' )
752+
expect(createNote.mock.calls[0][0].content).toBe('testing a form...')
751753
})
752754
```
753755

0 commit comments

Comments
 (0)