nodejs/test/parallel/test-zlib-const.js
Rich Trott 08eeddfa83
test: enforce strict mode in test-zlib-const
Instead of checking that assignments fail silently in sloppy mode, check
that they throw in strict mode.

PR-URL: https://github.com/nodejs/node/pull/56689
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2025-01-24 04:38:49 +00:00

29 lines
949 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const zlib = require('zlib');
assert.strictEqual(zlib.constants.Z_OK, 0,
[
'Expected Z_OK to be 0;',
`got ${zlib.constants.Z_OK}`,
].join(' '));
assert.throws(() => { zlib.constants.Z_OK = 1; },
TypeError, 'zlib.constants.Z_OK should be immutable');
assert.strictEqual(zlib.codes.Z_OK, 0,
`Expected Z_OK to be 0; got ${zlib.codes.Z_OK}`);
assert.throws(() => { zlib.codes.Z_OK = 1; },
TypeError, 'zlib.codes.Z_OK should be immutable');
assert.throws(() => { zlib.codes = { Z_OK: 1 }; },
TypeError, 'zlib.codes should be immutable');
assert.ok(Object.isFrozen(zlib.codes),
[
'Expected zlib.codes to be frozen, but Object.isFrozen',
`returned ${Object.isFrozen(zlib.codes)}`,
].join(' '));