Skip to content

Commit

Permalink
Merge pull request #22 from MapColonies/fix-null-value-freeze
Browse files Browse the repository at this point in the history
fix: support null valued config attributes
  • Loading branch information
ronenkapelian authored Dec 11, 2024
2 parents 4d781b5 + 49e6d28 commit 02387d2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export function deepFreeze<T>(obj: T): void {
const propNames = Object.getOwnPropertyNames(obj);
for (const name of propNames) {
const value = obj[name as keyof T];
if (typeof value === 'object') {
if (typeof value === 'object' && value !== null) {
deepFreeze(value);
}
}
Expand Down
43 changes: 43 additions & 0 deletions tests/helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'jest-extended';
import { deepFreeze } from '../src/utils/helpers';

describe('helpers', () => {
describe('#deepFreeze', () => {
it('should return frozen object', () => {
const data = {
name: 'I am parent',
child: {
name: 'I am child',
},
};

deepFreeze(data);
expect(data).toBeFrozen();
});

it('should freeze the input object that include null valued property without error', () => {
const data = {
name: null,
child: {
name: 'i am child',
},
};

deepFreeze(data);
expect(data).toBeFrozen();
});

it('should freeze the input object include nested property', () => {
const data = {
name: 'I am parent',
child: {
name: 'I am child',
},
};

deepFreeze(data);
const child = data.child;
expect(child).toBeFrozen();
});
});
});

0 comments on commit 02387d2

Please sign in to comment.