Skip to content

Commit

Permalink
Merge pull request #346 from Xotic750/slice
Browse files Browse the repository at this point in the history
[Tests] Add tests for `Array#slice`
  • Loading branch information
ljharb committed Nov 18, 2015
2 parents 62a3d8f + 8584079 commit 2a00600
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/spec/s-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -1540,4 +1540,32 @@ describe('Array', function () {
expect(obj[2]).toBeUndefined();
});
});

describe('#slice()', function () {
it('works on arrays', function () {
var arr = [1, 2, 3, 4];
var result = arr.slice(1, 3);
expect(result).toEqual([2, 3]);
});

it('is generic', function () {
var obj = { 0: 1, 1: 2, 2: 3, 3: 4, length: 4 };
var result = Array.prototype.slice.call(obj, 1, 3);
expect(result).toEqual([2, 3]);
});

it('works with arguments', function () {
var obj = (function () {
return arguments;
}(1, 2, 3, 4));
var result = Array.prototype.slice.call(obj, 1, 3);
expect(result).toEqual([2, 3]);
});

it('boxed string access', function () {
var obj = '1234';
var result = Array.prototype.slice.call(obj, 1, 3);
expect(result).toEqual(['2', '3']);
});
});
});

0 comments on commit 2a00600

Please sign in to comment.