UNPKG

@eureca/eureca-ui

Version:

UI component library of Eureca's user and admin apps

28 lines (21 loc) 887 B
import React from 'react'; import { FileUpload } from '../file-upload'; import { render, fireEvent } from '@testing-library/react'; const onChangeMock = jest.fn(); function renderAccordion({ fileType, onChange }) { return render(<FileUpload fileType={fileType} onChange={onChange} />); } describe('File Upload component', () => { it('triggers onChange', async () => { const { getByTestId } = renderAccordion({ onChange: onChangeMock }); const element = getByTestId('file-upload-button'); fireEvent.click(element); expect(onChangeMock).toHaveBeenCalledTimes(1); }); it('has a file type defined', async () => { const { getByTestId } = renderAccordion({ fileType: 'audio' }); const element = getByTestId('file-upload-button'); const hiddenInput = element.lastElementChild.lastElementChild; expect(hiddenInput.accept).toBe('audio/*'); }); });