| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,20 +5,17 @@ | |||
| 5 | 5 | require('../common'); | |
| 6 | 6 | const assert = require('assert'); | |
| 7 | 7 | const async_hooks = require('async_hooks'); | |
| 8 | - const non_function = 10; | ||
| 8 | + const nonFunctionArray = [null, -1, 1, {}, []]; | ||
| 9 | 9 | ||
| 10 | - typeErrorForFunction('init'); | ||
| 11 | - typeErrorForFunction('before'); | ||
| 12 | - typeErrorForFunction('after'); | ||
| 13 | - typeErrorForFunction('destroy'); | ||
| 14 | - typeErrorForFunction('promiseResolve'); | ||
| 15 | - | ||
| 16 | - function typeErrorForFunction(functionName) { | ||
| 17 | - assert.throws(() => { | ||
| 18 | - async_hooks.createHook({ [functionName]: non_function }); | ||
| 19 | - }, { | ||
| 20 | - code: 'ERR_ASYNC_CALLBACK', | ||
| 21 | - name: 'TypeError', | ||
| 22 | - message: `hook.${functionName} must be a function` | ||
| 10 | + ['init', 'before', 'after', 'destroy', 'promiseResolve'].forEach( | ||
| 11 | + (functionName) => { | ||
| 12 | + nonFunctionArray.forEach((nonFunction) => { | ||
| 13 | + assert.throws(() => { | ||
| 14 | + async_hooks.createHook({ [functionName]: nonFunction }); | ||
| 15 | + }, { | ||
| 16 | + code: 'ERR_ASYNC_CALLBACK', | ||
| 17 | + name: 'TypeError', | ||
| 18 | + message: `hook.${functionName} must be a function`, | ||
| 19 | + }); | ||
| 20 | + }); | ||
| 23 | 21 | }); | |
| 24 | - } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments