From 5e436f89e5f9b18afba5249f37734f8870da2e89 Mon Sep 17 00:00:00 2001 From: Matteo Rossi Date: Mon, 14 Oct 2019 17:39:39 +0200 Subject: [PATCH] test: add cb error test for fs.close() Provides some missing test coverage. PR-URL: https://github.com/nodejs/node/pull/29970 Reviewed-By: Jeremiah Senkpiel Reviewed-By: Rich Trott Reviewed-By: James M Snell --- test/parallel/test-fs-close-errors.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/parallel/test-fs-close-errors.js b/test/parallel/test-fs-close-errors.js index 42d990410f9848..6168d5c20ab8e5 100644 --- a/test/parallel/test-fs-close-errors.js +++ b/test/parallel/test-fs-close-errors.js @@ -17,3 +17,19 @@ const fs = require('fs'); assert.throws(() => fs.close(input), errObj); assert.throws(() => fs.closeSync(input), errObj); }); + +{ + // Test error when cb is not a function + const fd = fs.openSync(__filename, 'r'); + + const errObj = { + code: 'ERR_INVALID_CALLBACK', + name: 'TypeError' + }; + + ['', false, null, {}, []].forEach((input) => { + assert.throws(() => fs.close(fd, input), errObj); + }); + + fs.closeSync(fd); +}