forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-fs-make-callback.js
More file actions
31 lines (24 loc) · 930 Bytes
/
test-fs-make-callback.js
File metadata and controls
31 lines (24 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const cbTypeError = /^TypeError: "callback" argument must be a function$/;
const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}];
const { sep } = require('path');
const warn = 'Calling an asynchronous function without callback is deprecated.';
common.refreshTmpDir();
function testMakeCallback(cb) {
return function() {
// fs.mkdtemp() calls makeCallback() on its third argument
fs.mkdtemp(`${common.tmpDir}${sep}`, {}, cb);
};
}
common.expectWarning('DeprecationWarning', warn);
// Passing undefined/nothing calls rethrow() internally, which emits a warning
assert.doesNotThrow(testMakeCallback());
function invalidCallbackThrowsTests() {
callbackThrowValues.forEach((value) => {
assert.throws(testMakeCallback(value), cbTypeError);
});
}
invalidCallbackThrowsTests();