Skip to content

Commit d678f32

Browse files
author
Ammar Dodin
committed
💚 add unit tests for lib/content-type.ts
1 parent c6abb9d commit d678f32

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/unit/test.contentType.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const contentType = require('../../lib/content-type');
2+
const assert = require('assert');
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
describe('contentType', () => {
7+
it('should return content type from a filename', () => {
8+
const fname = 'fake.mp3';
9+
assert(contentType.fromFilename(fname) === 'audio/mp3');
10+
});
11+
it('should return content type from a File object', () => {
12+
const File = {
13+
name: 'fake.mp3'
14+
};
15+
assert(contentType.fromFilename(File) === 'audio/mp3');
16+
});
17+
it('should return undefined for an empty input', () => {
18+
assert(contentType.fromFilename({}) === undefined);
19+
});
20+
it('should return content type from a buffer', () => {
21+
const buffer = fs.readFileSync(
22+
path.join(__dirname, '../resources/blank.wav')
23+
);
24+
assert(contentType.fromHeader(buffer) === 'audio/wav');
25+
});
26+
});

0 commit comments

Comments
 (0)