|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +describe('Array', function () { |
| 4 | + describe('.push()', function () { |
| 5 | + it('should append a value', function () { |
| 6 | + var arr = []; |
| 7 | + arr.push('foo'); |
| 8 | + arr.push('bar'); |
| 9 | + expect(arr[0]).to.equal('foo'); |
| 10 | + expect(arr[1]).to.equal('bar'); |
| 11 | + }) |
| 12 | + |
| 13 | + it('should return the length', function () { |
| 14 | + var arr = []; |
| 15 | + var n = arr.push('foo'); |
| 16 | + expect(n).to.equal(1); |
| 17 | + n = arr.push('bar'); |
| 18 | + expect(n).to.equal(2); |
| 19 | + }) |
| 20 | + |
| 21 | + describe('with many arguments', function () { |
| 22 | + it('should add the values', function () { |
| 23 | + var arr = []; |
| 24 | + arr.push('foo', 'bar'); |
| 25 | + expect(arr[0]).to.equal('foo'); |
| 26 | + expect(arr[1]).to.equal('bar'); |
| 27 | + }) |
| 28 | + }) |
| 29 | + }) |
| 30 | + |
| 31 | + describe('.unshift()', function () { |
| 32 | + it('should prepend a value', function () { |
| 33 | + var arr = [1, 2, 3]; |
| 34 | + arr.unshift('foo'); |
| 35 | + expect(arr[0]).to.equal('foo'); |
| 36 | + expect(arr[1]).to.equal(1); |
| 37 | + }) |
| 38 | + |
| 39 | + it('should return the length', function () { |
| 40 | + var arr = []; |
| 41 | + var n = arr.unshift('foo'); |
| 42 | + expect(n).to.equal(1); |
| 43 | + n = arr.unshift('bar'); |
| 44 | + expect(n).to.equal(2); |
| 45 | + }) |
| 46 | + |
| 47 | + describe('with many arguments', function () { |
| 48 | + it('should add the values', function () { |
| 49 | + var arr = []; |
| 50 | + arr.unshift('foo', 'bar'); |
| 51 | + expect(arr[0]).to.equal('foo'); |
| 52 | + expect(arr[1]).to.equal('bar'); |
| 53 | + }) |
| 54 | + }) |
| 55 | + }) |
| 56 | + |
| 57 | + describe('.pop()', function () { |
| 58 | + it('should remove and return the last value', function () { |
| 59 | + var arr = [1, 2, 3]; |
| 60 | + expect(arr.pop()).to.equal(3); |
| 61 | + expect(arr.pop()).to.equal(2); |
| 62 | + expect(arr).to.have.length(1); |
| 63 | + }) |
| 64 | + }) |
| 65 | + |
| 66 | + describe('.shift()', function () { |
| 67 | + it('should remove and return the first value', function () { |
| 68 | + var arr = [1, 2, 3]; |
| 69 | + expect(arr.shift()).to.equal(1); |
| 70 | + expect(arr.shift()).to.equal(2); |
| 71 | + expect(arr).to.have.length(1); |
| 72 | + }) |
| 73 | + }) |
| 74 | +}) |
| 75 | + |
0 commit comments