|
1 | 1 | import { canNotMutateObjectDeep } from '../common/index.mjs'; |
2 | 2 | import assert from 'node:assert'; |
| 3 | +import { promisify } from 'node:util'; |
3 | 4 |
|
4 | 5 | // Test common.canNotMutateObjectDeep() |
5 | 6 |
|
@@ -197,3 +198,28 @@ function setPrototypeOfQuux(root) { |
197 | 198 | assert.deepStrictEqual(canNotMutateObjectDeep({ target }), { target }); |
198 | 199 | assert.deepStrictEqual(canNotMutateObjectDeep([ target ]), [ target ]); |
199 | 200 | }); |
| 201 | + |
| 202 | +// Test that passed functions keep working correctly |
| 203 | +{ |
| 204 | + const fn = () => 'blep'; |
| 205 | + fn.foo = {}; |
| 206 | + const fnImmutableView = canNotMutateObjectDeep(fn); |
| 207 | + assert.deepStrictEqual(fnImmutableView, fn); |
| 208 | + |
| 209 | + // The function works |
| 210 | + assert.strictEqual(fn(), 'blep'); |
| 211 | + assert.strictEqual(fnImmutableView(), 'blep'); |
| 212 | + |
| 213 | + // The original function is not deeply frozen |
| 214 | + fn.foo.bar = 'baz'; |
| 215 | + assert.strictEqual(fn.foo.bar, 'baz'); |
| 216 | + assert.strictEqual(fnImmutableView.foo.bar, 'baz'); |
| 217 | + |
| 218 | + // The original function is not frozen |
| 219 | + fn.qux = 'quux'; |
| 220 | + assert.strictEqual(fn.qux, 'quux'); |
| 221 | + assert.strictEqual(fnImmutableView.qux, 'quux'); |
| 222 | + |
| 223 | + // Redefining util.promisify.custom also works |
| 224 | + await promisify(promisify(fn))(); |
| 225 | +} |
0 commit comments