updeep-remeda/test/freeze-spec.js

66 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-08-02 07:15:52 +00:00
import { expect } from 'chai';
import freeze from '../lib/freeze';
2015-08-05 05:28:31 +00:00
describe('u.freeze', () => {
2015-08-02 07:15:52 +00:00
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;
});
2015-08-03 17:37:26 +00:00
it('handles null objects', () => {
const obj = { foo: null };
freeze(obj);
expect(Object.isFrozen(obj)).to.be.true;
});
2015-08-05 04:56:01 +00:00
it('returns the same object', () => {
const obj = {};
const result = freeze(obj);
expect(result).to.equal(obj);
});
2015-08-02 07:15:52 +00:00
});