forked from nodejs/abi-stable-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: extended test to makeCallback cb type check
makeCallback and makeStatsCallback are both tested intedependently. PR-URL: nodejs/node#12140 Fixes: nodejs/node#12136 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
- Loading branch information
1 parent
7eb1b46
commit 53828e8
Showing
2 changed files
with
47 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'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 warn = 'Calling an asynchronous function without callback is deprecated.'; | ||
|
||
function testMakeStatsCallback(cb) { | ||
return function() { | ||
// fs.stat() calls makeStatsCallback() on its second argument | ||
fs.stat(__filename, cb); | ||
}; | ||
} | ||
|
||
common.expectWarning('DeprecationWarning', warn); | ||
|
||
// Verify the case where a callback function is provided | ||
assert.doesNotThrow(testMakeStatsCallback(common.noop)); | ||
|
||
// Passing undefined/nothing calls rethrow() internally, which emits a warning | ||
assert.doesNotThrow(testMakeStatsCallback()); | ||
|
||
function invalidCallbackThrowsTests() { | ||
callbackThrowValues.forEach((value) => { | ||
assert.throws(testMakeStatsCallback(value), cbTypeError); | ||
}); | ||
} | ||
|
||
invalidCallbackThrowsTests(); |