updeep-remeda/test/freeze.js
2015-08-02 00:17:22 -07:00

54 lines
1.1 KiB
JavaScript

import { expect } from 'chai';
import freeze from '../lib/freeze';
describe('freeze', () => {
afterEach(() => {
delete process.env.NODE_ENV;
});
it('freezes objects', () => {
const obj = {};
freeze(obj);
expect(Object.isFrozen(obj)).to.be.true;
});
it('freezes nested objects', () => {
const obj = { foo: { bar: 3 } };
freeze(obj);
expect(Object.isFrozen(obj.foo)).to.be.true;
});
it('freezes nested arrays', () => {
const obj = [[0]];
freeze(obj);
expect(Object.isFrozen(obj)).to.be.true;
expect(Object.isFrozen(obj[0])).to.be.true;
});
it('ignores functions', () => {
const obj = { foo: () => 1 };
freeze(obj);
expect(Object.isFrozen(obj.foo)).to.be.false;
});
it('does not freeze children if the parent is already frozen', () => {
const obj = { foo: {} };
Object.freeze(obj);
freeze(obj);
expect(Object.isFrozen(obj.foo)).to.be.false;
});
it('does not freeze in production', () => {
process.env.NODE_ENV = 'production';
const obj = {};
freeze(obj);
expect(Object.isFrozen(obj)).to.be.false;
});
});