0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-fs-makeStatsCallback.js
Mohammed Keyvanzadeh 8c4b8b201a
lib: replace validator and error
Refs: https://github.com/nodejs/node/pull/41660

PR-URL: https://github.com/nodejs/node/pull/41678
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-02-05 08:36:48 -08:00

27 lines
693 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}];
function testMakeStatsCallback(cb) {
return function() {
// fs.stat() calls makeStatsCallback() on its second argument
fs.stat(__filename, cb);
};
}
// Verify the case where a callback function is provided
testMakeStatsCallback(common.mustCall())();
function invalidCallbackThrowsTests() {
callbackThrowValues.forEach((value) => {
assert.throws(testMakeStatsCallback(value), {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
});
});
}
invalidCallbackThrowsTests();