From 49e6d2835ddca24eb767b4880ffb9c7215992aae Mon Sep 17 00:00:00 2001 From: ronenk1 Date: Wed, 11 Dec 2024 09:49:17 +0200 Subject: [PATCH] test: add and fix relevant tests --- tests/helpers.spec.ts | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/tests/helpers.spec.ts b/tests/helpers.spec.ts index d5ed8c4..a409ffb 100644 --- a/tests/helpers.spec.ts +++ b/tests/helpers.spec.ts @@ -1,3 +1,4 @@ +import 'jest-extended'; import { deepFreeze } from '../src/utils/helpers'; describe('helpers', () => { @@ -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(); }); }); });