diff --git a/lib/freeze.js b/lib/freeze.js index cd1ae6a..dd852a8 100644 --- a/lib/freeze.js +++ b/lib/freeze.js @@ -1,4 +1,6 @@ function isFreezable(obj) { + if (obj === null) return false; + return Array.isArray(obj) || typeof obj === 'object'; } diff --git a/test/freeze.js b/test/freeze.js index ca4a381..91c4d5f 100644 --- a/test/freeze.js +++ b/test/freeze.js @@ -50,4 +50,10 @@ describe('freeze', () => { expect(Object.isFrozen(obj)).to.be.false; }); + + it('handles null objects', () => { + const obj = { foo: null }; + freeze(obj); + expect(Object.isFrozen(obj)).to.be.true; + }); });