Created
August 30, 2022 16:50
-
-
Save jayjayjpg/02bd925ccd9cf38a152ba07aac3890c1 to your computer and use it in GitHub Desktop.
test-user-interactions-in-js-apps-accurately-with-emulated-events-example-5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import '@testing-library/jest-dom'; | |
import * as React from 'react'; | |
import Upload from '../src/Upload'; | |
import {render, fireEvent, waitFor, screen} from '@testing-library/react'; | |
test('allows uploading files', async () => { | |
render(<Upload | |
title="Update Mokedexx" | |
description="Add your new companions here 🇰🇷" | |
label="업로드 한국 모켓몬" | |
/>); | |
// the text field is empty initially | |
let textField = await screen.findByTestId('text-field'); | |
expect(textField).toHaveValue(''); | |
// the file upload is emulated | |
let uploadField = await screen.findByTestId('file-upload-field'); | |
let fileBlob = { files: [new Blob(['꼬부기'])] }; | |
fireEvent.change(uploadField, { target: fileBlob }); | |
// the text area is updated with the file content | |
await waitFor(() => expect(textField).toHaveValue('꼬부기')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment