I would expect this test to pass but it fails:
it('should consume files on drop', () => {
const mock = jest.fn();
const file = new File(['file'], 'file.txt', { type: 'text/plain' });
const fileList = [file];
render(<DropZone onDocumentDrop={mock} />);
const dropZone = screen.getByTestId('dropZone');
const dropEvent = createEvent.drop(dropZone);
Object.defineProperty(dropEvent, 'dataTransfer', {
value: {
files: {
item: (index: number) => fileList[index],
length: fileList.length,
},
},
});
fireEvent(dropZone, dropEvent);
expect(dropZone).toBeInTheDocument();
expect(mock).toHaveBeenCalled();
expect(mock).toHaveBeenCalledWith({
item: (index: number) => fileList[index],
length: 1,
});
});
Jest reports that:
expect(jest.fn()).toHaveBeenCalledWith(...expected)
- Expected
+ Received
- {"item": [Function item], "length": 1},
+ {"item": [Function item], "length": 1},
I am not sure how to make it pass or get anymore insight into what is wrong?