UNPKG

babel-plugin-elsa

Version:

A babel plugin for replacing object and array literals with immutable versions

76 lines (65 loc) 2.25 kB
/* eslint-disable func-names */ /* eslint-disable strict */ const assert = require('assert'); const FrozenArray = require('../frozen_array'); describe('FrozenArray', () => { before(function () { this.farr = new FrozenArray(4, 3, 11, 19, 13, 0); this.farrSingle = new FrozenArray(4); }); it('is an array', function () { assert.deepEqual(this.farr, [4, 3, 11, 19, 13, 0]); assert.deepEqual(this.farrSingle, [4]); assert(this.farr.constructor === FrozenArray); assert(this.farr instanceof FrozenArray); assert(this.farr instanceof Array); assert(Array.isArray(this.farr)); }); it('is frozen', function () { assert(Object.isFrozen(this.farr)); assert.throws(() => { 'use strict'; this.farr[0] = 26; }, TypeError); }); describe('#push', () => { it('returns array with value pushed on', function () { assert.deepEqual(this.farr.push(3), [4, 3, 11, 19, 13, 0, 3]); assert(Object.isFrozen(this.farr.push(3))); }); }); describe('#pop', () => { it('returns array with new array and value', function () { assert.deepEqual(this.farr.pop(), [[4, 3, 11, 19, 13], 0]); assert(Object.isFrozen(this.farr.pop())); assert(Object.isFrozen(this.farr.pop()[0])); }); }); describe('#sort', () => { it('returns a sorted array', function () { const sorted = this.farr.sort((a, b) => a - b); assert.deepEqual(sorted, [0, 3, 4, 11, 13, 19]); assert(Object.isFrozen(sorted)); }); }); describe('#reverse', () => { it('returns a reversed array', function () { const reversed = this.farr.reverse(); assert.deepEqual(reversed, [0, 13, 19, 11, 3, 4]); assert(Object.isFrozen(reversed)); }); }); describe('#slice', () => { it('returns a sliced array', function () { const sliced = this.farr.slice(1, 3); assert.deepEqual(sliced, [3, 11]); assert(Object.isFrozen(sliced)); assert.deepEqual(this.farr.slice(1, 2), [3]); // The single value has caused bugs, test needed }); }); describe('#fill', () => { it('returns an array filled in with given value', function () { assert.deepEqual(this.farr.fill(1), [1, 1, 1, 1, 1, 1]); }); }); });