From 858407953e7732c768b2aff1e7ada21f8addcd2b Mon Sep 17 00:00:00 2001 From: Xotic750 Date: Tue, 17 Nov 2015 16:12:31 +0100 Subject: [PATCH] Add tests for `Array#slice`. Important to be sure of functionality for future `call` and `apply` fixes. Split into 2 `it`s as per comments. --- tests/spec/s-array.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/spec/s-array.js b/tests/spec/s-array.js index 6077b127..0b7c88ed 100644 --- a/tests/spec/s-array.js +++ b/tests/spec/s-array.js @@ -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']); + }); + }); });