Skip to content

Commit c78c4bc

Browse files
committed
fix promise rejection error
1 parent bbac474 commit c78c4bc

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
const fs = require('fs');
33
const pathExists = require('path-exists');
44

5-
module.exports = filename => new Promise(resolve => {
5+
module.exports = filename => new Promise((resolve, reject) => {
66
if (pathExists.sync(filename)) {
77
const stats = fs.statSync(filename);
88
resolve(stats.size);
99
}
1010

11-
throw new Error(`File "${filename}" not found`);
11+
reject(new Error(`File "${filename}" not found`));
1212
});
1313

1414
module.exports.sync = filename => {

test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ test('small file sync', t => {
2323
});
2424

2525
test('invalid args promise', async t => {
26-
t.throws(() => {
27-
fileBytes.sync('invalidFileName.txt');
28-
}, Error);
26+
try {
27+
await fileBytes('invalidFileName.txt');
28+
t.fail('Exception was not thrown');
29+
} catch (err) {
30+
t.truthy(err);
31+
}
2932
});
3033

3134
test('empty file promise', async t => {

0 commit comments

Comments
 (0)