@@ -689,19 +689,20 @@ Jos syötekentälle olisi määritelty <i>label</i>, voisi kyseisen syötekentä
689689Testi 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 }) => {
735736Nyt 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