Skip to content

Commit

Permalink
test: add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Wxh16144 committed Aug 30, 2024
1 parent c1ceb94 commit c90d091
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/uploader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,31 @@ describe('uploader', () => {
await new Promise(resolve => setTimeout(resolve, 100));
await new Promise(resolve => setTimeout(resolve, 2000));
});

it('should pass file to request', done => {
const fakeRequest = jest.fn((file) => {
expect(file).toEqual(expect.objectContaining({
filename: 'file', // <= https://github.com/react-component/upload/pull/574
file: expect.any(File),
method: 'post',
onError: expect.any(Function),
onProgress: expect.any(Function),
onSuccess: expect.any(Function),
data: expect.anything(),
}));

done();
});

const { container } = render(<Upload customRequest={fakeRequest} />);
const input = container.querySelector('input')!;
const files = [new File([''], 'success.png', { type: 'image/png' })];
Object.defineProperty(files, 'item', {
value: i => files[i],
});

fireEvent.change(input, { target: { files } });
});
});

describe('directory uploader', () => {
Expand Down

0 comments on commit c90d091

Please sign in to comment.