Skip to content

Commit 9fb2eec

Browse files
committed
index.d.ts: make Options#errorCallback optional
This commit adds a test that checks different value types for `errorCallback`, but we must skip it because it causes issues with the garbage collection. Signed-off-by: Paul Maréchal <[email protected]>
1 parent c031e4c commit 9fb2eec

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ declare module 'nsfw' {
6060
interface Options {
6161
/** time in milliseconds to debounce the event callback */
6262
debounceMS?: number;
63-
/** callback to fire in the case of errors */
64-
errorCallback: (err: any) => void
63+
/** callback to fire in the case of errors */
64+
errorCallback?: (err: any) => void
6565
}
6666
}
6767

js/spec/index-spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,31 @@ describe('Node Sentinel File Watcher', function() {
562562
watch = null;
563563
}
564564
});
565+
566+
it('Can pass falsy values to errorCallback', async function() {
567+
const ok = [undefined, null, 0, '', false];
568+
const notOk = [1, true, 'a', {}, []];
569+
await Promise.all([
570+
...ok.map(async errorCallback => nsfw(
571+
workDir,
572+
() => {},
573+
{ errorCallback }
574+
)),
575+
...notOk.map(async errorCallback => {
576+
try {
577+
await nsfw(
578+
workDir,
579+
() => {},
580+
{ errorCallback },
581+
);
582+
} catch (error) {
583+
assert.ok(error.message === 'options.errorCallback must be a function.');
584+
return;
585+
}
586+
assert.fail('nsfw must error if errorCallback is not a function nor a falsy value');
587+
})
588+
]);
589+
});
565590
});
566591

567592
describe('Stress', function() {

0 commit comments

Comments
 (0)