Skip to content

Commit

Permalink
Add tests for Array#slice. Important to be sure of functionality fo…
Browse files Browse the repository at this point in the history
…r future `call` and `apply` fixes.

Split into 2 `it`s as per comments.
  • Loading branch information
Xotic750 committed Nov 17, 2015
1 parent 62a3d8f commit 8584079
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 8584079

Please sign in to comment.