Skip to content

Commit be6b1f6

Browse files
committed
squash: extend test
1 parent 9212fad commit be6b1f6

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

test/parallel/test-common-can-not-mutate-object-deep.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { canNotMutateObjectDeep } from '../common/index.mjs';
22
import assert from 'node:assert';
3+
import { promisify } from 'node:util';
34

45
// Test common.canNotMutateObjectDeep()
56

@@ -197,3 +198,28 @@ function setPrototypeOfQuux(root) {
197198
assert.deepStrictEqual(canNotMutateObjectDeep({ target }), { target });
198199
assert.deepStrictEqual(canNotMutateObjectDeep([ target ]), [ target ]);
199200
});
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

Comments
 (0)