summaryrefslogtreecommitdiff
path: root/test/slice.js
blob: 70205264dc9f51e2294210ed81ca1df73ea5ba6d (plain)
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
var slice = require('../lib/internal/slice').default;
var expect = require('chai').expect;

describe('slice', function() {
    it('should slice arrays', function() {
        var arr = ['foo', 'bar', 'baz'];
        var result = slice(arr, 2);
        expect(arr).to.eql(['foo', 'bar', 'baz']);
        expect(result).to.eql(['baz']);
    });

    it('should handle ArrayLike objects', function() {
        var args = {0: 'foo', 1: 'bar', 2: 'baz', length: 3};
        var result = slice(args, 1);
        expect(result).to.be.an('array');
        expect(result).to.eql(['bar', 'baz']);
    });

    it('should handle arguments', function() {
        var foo = function() {
            return slice(arguments, 1);
        };
        var result = foo.apply(null, ['foo', 'bar', 'baz']);
        expect(result).to.be.an('array');
        expect(result).to.eql(['bar', 'baz']);
    });

    it('should return an empty array on an invalid start', function() {
        var result = slice(['foo', 'bar', 'baz'], 10);
        expect(result).to.be.an('array').that.is.empty;
    });
});