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