Skip to content

Commit 69b9591

Browse files
author
Roland Groza
committed
fix: make {path, type} enumerable and close #7
1 parent 9638152 commit 69b9591

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/file.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// tslint:disable: forin
12
import {COMMON_MIME_TYPES, toFileWithPath} from './file';
23

34
describe('toFile()', () => {
@@ -22,6 +23,21 @@ describe('toFile()', () => {
2223
expect(fileWithPath.path).toBe(path);
2324
});
2425

26+
test('{path} is enumerable', () => {
27+
const path = '/test/test.json';
28+
const file = new File([], 'test.json');
29+
const fileWithPath = toFileWithPath(file, path);
30+
31+
expect(Object.keys(fileWithPath)).toContain('path');
32+
33+
const keys = [];
34+
for (const key in fileWithPath) {
35+
keys.push(key);
36+
}
37+
38+
expect(keys).toContain('path');
39+
});
40+
2541
it('uses the File {name} as {path} if not provided', () => {
2642
const name = 'test.json';
2743
const file = new File([], name);
@@ -50,6 +66,20 @@ describe('toFile()', () => {
5066
}
5167
});
5268

69+
test('{type} is enumerable', () => {
70+
const file = new File([], 'test.gif');
71+
const fileWithPath = toFileWithPath(file);
72+
73+
expect(Object.keys(fileWithPath)).toContain('type');
74+
75+
const keys = [];
76+
for (const key in fileWithPath) {
77+
keys.push(key);
78+
}
79+
80+
expect(keys).toContain('type');
81+
});
82+
5383
it('sets the {type} from extension regardless of case', () => {
5484
const types = Array.from(COMMON_MIME_TYPES.values());
5585
const files = Array.from(COMMON_MIME_TYPES.keys())

src/file.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export function toFileWithPath(file: File, path?: string): FileWithPath {
2828
? webkitRelativePath
2929
: file.name,
3030
writable: false,
31-
configurable: false
31+
configurable: false,
32+
enumerable: true
3233
});
3334
return f;
3435
}
@@ -53,7 +54,8 @@ function withMimeType(file: File) {
5354
Object.defineProperty(file, 'type', {
5455
value: type,
5556
writable: false,
56-
configurable: false
57+
configurable: false,
58+
enumerable: true
5759
});
5860
}
5961
}

0 commit comments

Comments
 (0)