-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial tests for isFile and isFileList
- Loading branch information
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |