You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: this code follows the Test Drive the API Call of a React Form with React Testing Library video from Testing JavaScript course (it is modified to use userEvent and screen, as the video in the course is out of date).
Test
importReactfrom'react';importuserEventfrom'@testing-library/user-event';import{render,screen}from'@testing-library/react';import{savePostasmockSavePost}from'../api';import{Editor}from'../post-editor-01-markup';jest.mock('../api');test('renders a form with title, content, tags, and a submit button',()=>{mockSavePost.mockResolvedValueOnce()render(<Editor/>);constfakePost={title: 'Test Title',content: 'Test Content',tags: ['tag1','tag2']};consttitleInput=screen.getByLabelText(/title/i,{});userEvent.type(titleInput,fakePost.title);constcontentInput=screen.getByLabelText(/content/i,{});userEvent.type(contentInput,fakePost.content);// Here is the issue.consttagsInput=screen.getByLabelText(/tags/i,{});userEvent.type(tagsInput,fakePost.tags.join(','))constsubmitButton=screen.getByText(/submit/i,{});userEvent.click(submitButton);expect(submitButton).toBeDisabled();expect(mockSavePost).toHaveBeenCalledWith(fakePost)expect(mockSavePost).toHaveBeenCalledTimes(1);})
Problem description:
It should type into the text area the correct value (i.e. 'Test Content'). As far as I am concerned, this only happened to the textarea input, and not the other inputs.
The text was updated successfully, but these errors were encountered:
@testing-library/user-event
version: 13.5.0Testing Framework and version: jest@24.9.0
DOM Environment: jsdom
Note: this code follows the Test Drive the API Call of a React Form with React Testing Library video from Testing JavaScript course (it is modified to use userEvent and screen, as the video in the course is out of date).
Test
Component
What you did:
I used userEvent to type into a text area the text: 'Test Content' in line: userEvent.type(contentInput, fakePost.content);
What happened:
Instead of userEvent typing in: 'Test Content', it typed in: "est ContentT"
Error Message:
Problem description:
It should type into the text area the correct value (i.e. 'Test Content'). As far as I am concerned, this only happened to the textarea input, and not the other inputs.
The text was updated successfully, but these errors were encountered: