Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/file-selector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,20 @@ it('should use getAsFileSystemHandle when available', async () => {
expect(file.path).toBe(`./${name}`);
});

it('Reproduces Bug #106', async () => {
const name = 'test.json';
const mockFile = createFile(name, {ping: true}, {
type: 'application/json'
});
const item = dataTransferItemWithFsHandle(mockFile, null);
const evt = dragEvtFromFilesAndItems([], [item]);

const files = await fromEvent(evt);
expect(files).toHaveLength(1);
const [file] = files as FileWithPath[];
expect(file.path).toBe(`./${name}`);
});

function dragEvtFromItems(items: DataTransferItem | DataTransferItem[], type: string = 'drop'): DragEvent {
return {
type,
Expand Down Expand Up @@ -374,7 +388,7 @@ function dataTransferItemFromEntry(entry: FileEntry | DirEntry, file?: File): Da
} as any;
}

function dataTransferItemWithFsHandle(file?: File, h?: FileSystemFileHandle): DataTransferItem {
function dataTransferItemWithFsHandle(file?: File, h?: FileSystemFileHandle | null): DataTransferItem {
return {
kind: 'file',
getAsFile() {
Expand Down
Loading