Skip to content

Commit

Permalink
test: add and fix relevant tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ronenkapelian committed Dec 11, 2024
1 parent 410ec55 commit 49e6d28
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions tests/helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'jest-extended';
import { deepFreeze } from '../src/utils/helpers';

describe('helpers', () => {
Expand All @@ -9,27 +10,34 @@ describe('helpers', () => {
name: 'I am child',
},
};

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

const action = () => {
data.name = 'i try to change'; // try to change freezed object
it('should freeze the input object that include null valued property without error', () => {
const data = {
name: null,
child: {
name: 'i am child',
},
};
expect(action).toThrow(/Cannot assign to read only property/);

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

it('should return frozen object with nested null value without error', () => {
it('should freeze the input object include nested property', () => {
const data = {
name: 'I am parent',
child: {
name: null,
name: 'I am child',
},
};
deepFreeze(data);

const action = () => {
data.name = 'i try to change'; // try to change freezed object
};
expect(action).toThrow(/Cannot assign to read only property/);
deepFreeze(data);
const child = data.child;
expect(child).toBeFrozen();
});
});
});

0 comments on commit 49e6d28

Please sign in to comment.