|
1 | 1 | 'use strict';
|
2 |
| -require('../common'); |
| 2 | +const common = require('../common'); |
3 | 3 | const assert = require('assert');
|
4 | 4 | const fs = require('fs');
|
| 5 | +const cbTypeError = /^TypeError: "callback" argument must be a function$/; |
| 6 | +const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}]; |
5 | 7 |
|
6 |
| -function test(cb) { |
| 8 | +const { sep } = require('path'); |
| 9 | + |
| 10 | +common.refreshTmpDir(); |
| 11 | + |
| 12 | +function testMakeCallback(cb) { |
7 | 13 | return function() {
|
8 |
| - // fs.stat() calls makeCallback() on its second argument |
9 |
| - fs.stat(__filename, cb); |
| 14 | + // fs.mkdtemp() calls makeCallback() on its third argument |
| 15 | + fs.mkdtemp(`${common.tmpDir}${sep}`, {}, cb); |
10 | 16 | };
|
11 | 17 | }
|
12 | 18 |
|
13 |
| -// Verify the case where a callback function is provided |
14 |
| -assert.doesNotThrow(test(function() {})); |
| 19 | +// Passing undefined/nothing calls rethrow() internally |
| 20 | +assert.doesNotThrow(testMakeCallback()); |
15 | 21 |
|
16 |
| -// Passing undefined calls rethrow() internally, which is fine |
17 |
| -assert.doesNotThrow(test(undefined)); |
| 22 | +function invalidCallbackThrowsTests() { |
| 23 | + callbackThrowValues.forEach((value) => { |
| 24 | + assert.throws(testMakeCallback(value), cbTypeError); |
| 25 | + }); |
| 26 | +} |
18 | 27 |
|
19 |
| -// Anything else should throw |
20 |
| -assert.throws(test(null)); |
21 |
| -assert.throws(test(true)); |
22 |
| -assert.throws(test(false)); |
23 |
| -assert.throws(test(1)); |
24 |
| -assert.throws(test(0)); |
25 |
| -assert.throws(test('foo')); |
26 |
| -assert.throws(test(/foo/)); |
27 |
| -assert.throws(test([])); |
28 |
| -assert.throws(test({})); |
| 28 | +invalidCallbackThrowsTests(); |
0 commit comments