Skip to content

Commit

Permalink
Initial tests for isFile and isFileList
Browse files Browse the repository at this point in the history
  • Loading branch information
bgausden committed Aug 26, 2023
1 parent 78096c5 commit 1871bd0
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/isFile.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { assert } from 'chai';
import { isFile } from '../src/index.js';

describe('test isFile', function () {
/* it('test isFile', function (done) {
assert.equal(isFile('test'), false);
assert.equal(isFile(new File([''], 'test')), true);
assert.equal(isFile({}), false);
assert.equal(isFile(1), false);
assert.equal(isFile(true), false);
assert.equal(isFile(null), false);
assert.equal(isFile(undefined), false);
done();
}) */
it('should return false for a string', function (done) {
assert.equal(isFile('test'), false);
done();
});

it('should return true for a File object', function (done) {
assert.equal(isFile(new File([''], 'test')), true);
done();
});

it('should return false for an empty object', function (done) {
assert.equal(isFile({}), false);
done();
});

it('should return false for a number', function (done) {
assert.equal(isFile(1), false);
done();
});

it('should return false for a boolean', function (done) {
assert.equal(isFile(true), false);
done();
});

it('should return false for null', function (done) {
assert.equal(isFile(null), false);
done();
});

it('should return false for undefined', function (done) {
assert.equal(isFile(undefined), false);
done();
});
})
49 changes: 49 additions & 0 deletions test/isFileList.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { assert } from 'chai';
import { describe, it } from 'mocha';
import { isFileList } from '../src/index.js';

class MockFileList {
length: number;
item: (index: number) => File;

constructor(files: File[]) {
this.length = files.length;
this.item = (index: number) => files[index];
}

[Symbol.iterator]() {
let index = 0;
const files = this.item;
return {
next(): IteratorResult<File> {
if (index < files.length) {
return { value: files(index++), done: false };
} else {
return { value: null, done: true };
}
}
}
}
}



describe('test isFileList', function () {
// @ts-ignore
global.FileList = MockFileList;
let fileList = new MockFileList(Array<File>(new File([''], 'test')));
it('should not throw for FileList', function (done) {
assert.doesNotThrow(() => isFileList(fileList))
done();
})
it('should throw for {}', function (done) {
assert.throws(function () {
isFileList({});
});
done();
})

after(() => {
Reflect.deleteProperty(global, 'FileList')
})
})

0 comments on commit 1871bd0

Please sign in to comment.