|
| 1 | +/*global describe, it */ |
| 2 | + |
| 3 | +const expect = require('chai').expect |
| 4 | +const fs = require('fs') |
| 5 | +const jsdom = require('mocha-jsdom') |
| 6 | +const path = require('path') |
| 7 | + |
| 8 | +describe('arrays', () => { |
| 9 | + jsdom({ |
| 10 | + src: fs.readFileSync(path.resolve(__dirname, '..', 'arrays.js'), 'utf-8') |
| 11 | + }) |
| 12 | + |
| 13 | + describe('chocolateBars', () => { |
| 14 | + it('is an array containing "snickers", "hundred grand", "kitkat", and "skittles"', () => { |
| 15 | + expect(chocolateBars).to.eql['snickers', 'hundred grand', 'kitkat', 'skittles'] |
| 16 | + }) |
| 17 | + }) |
| 18 | + |
| 19 | + describe('addElementToBeginningOfArray(array, element)', () => { |
| 20 | + it('adds an `element` to the beginning of an `array`', () => { |
| 21 | + expect(addElementToBeginningOfArray([1], 'foo')).to.eql(['foo', 1]) |
| 22 | + }) |
| 23 | + |
| 24 | + it('does not alter `array`', () => { |
| 25 | + const array = [1] |
| 26 | + |
| 27 | + addElementToBeginningOfArray(array, 'foo') |
| 28 | + |
| 29 | + expect(array).to.eql(array) |
| 30 | + }) |
| 31 | + }) |
| 32 | + |
| 33 | + describe('descructivelyAddElementToBeginningOfArray(array, element)', () => { |
| 34 | + it('adds an `element` to the beginning of an `array`', () => { |
| 35 | + expect(descructivelyAddElementToBeginningOfArray([1], 'foo')).to.eql(['foo', 1]) |
| 36 | + }) |
| 37 | + |
| 38 | + it('alters `array`', () => { |
| 39 | + const array = [1] |
| 40 | + |
| 41 | + descructivelyAddElementToBeginningOfArray(array, 'foo') |
| 42 | + |
| 43 | + expect(array).to.eql(['foo', 1]) |
| 44 | + }) |
| 45 | + }) |
| 46 | + |
| 47 | + describe('addElementToEndOfArray(array, element)', () => { |
| 48 | + it('adds an `element` to the end of an `array`', () => { |
| 49 | + expect(addElementToEndOfArray([1], 'foo')).to.eql([1, 'foo']) |
| 50 | + }) |
| 51 | + |
| 52 | + it('does not alter `array`', () => { |
| 53 | + const array = [1] |
| 54 | + |
| 55 | + addElementToEndOfArray(array, 'foo') |
| 56 | + |
| 57 | + expect(array).to.eql(array) |
| 58 | + }) |
| 59 | + }) |
| 60 | + |
| 61 | + describe('destructivelyAddElementToEndOfArray(array, element)', () => { |
| 62 | + it('adds an `element` to the end of an `array`', () => { |
| 63 | + expect(destructivelyAddElementToEndOfArray([1], 'foo')).to.eql([1, 'foo']) |
| 64 | + }) |
| 65 | + |
| 66 | + it('alters `array`', () => { |
| 67 | + const array = [1] |
| 68 | + |
| 69 | + destructivelyAddElementToEndOfArray(array, 'foo') |
| 70 | + |
| 71 | + expect(array).to.eql([1, 'foo']) |
| 72 | + }) |
| 73 | + }) |
| 74 | + |
| 75 | + describe('accessElementAtArray(array, index)', () => { |
| 76 | + it('accesses the element in `array` at the given `index`', () => { |
| 77 | + expect(accessElementInArray([1, 2, 3], 2)).to.equal(3) |
| 78 | + }) |
| 79 | + }) |
| 80 | + |
| 81 | + describe('removeElementFromBeginningOfArray(array)', () => { |
| 82 | + it('removes the first element from the `array`', () => { |
| 83 | + expect(removeElementFromBeginningOfArray([1, 2, 3])).to.eql([2, 3]) |
| 84 | + }) |
| 85 | + }) |
| 86 | + |
| 87 | + describe('removeElementFromEndOfArray(array)', () => { |
| 88 | + it('removes the last element from the `array`', () => { |
| 89 | + expect(removeElementFromEndOfArray([1, 2, 3])).to.eql([1, 2]) |
| 90 | + }) |
| 91 | + }) |
| 92 | +}) |
0 commit comments