import {expect} from "chai"
import {deepFreeze} from "../../../source/util/freeze.mjs";


describe('deepFreeze', function () {

    describe('deepFreeze an object', function () {

        it('should freeze object', function () {

            let obj1 = {
                a: {
                    b: {
                        c:1
                    }
                }
            };
            
            let obj2 = {
                a: {
                    b: {
                        c:2
                    }
                }
            };

            expect(obj2).to.not.eql(obj1)
            obj1.a.b.c = 2;
            expect(obj2).to.eql(obj1);

            const obj1Freezed = deepFreeze(obj1);

            expect(obj2).to.eql(obj1Freezed);

            try {
                // https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
                // no change to the object, exception depends on mode (strict ES 2015, etc)
                obj1Freezed.a.b.c = 3    
            } catch (_) {

            }

            expect(obj2).to.eql(obj1Freezed);
            
            
        });

    });


});