Skip to content
This repository has been archived by the owner on Mar 11, 2018. It is now read-only.

Commit

Permalink
Merge 605c796 into f23f2b9
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-tan committed Mar 3, 2016
2 parents f23f2b9 + 605c796 commit db67694
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
'use strict';

var isArray = Array.isArray || function(object) {
return Object.prototype.toString.call(object) === '[object Array]';
};

module.exports = function(constants) {
if (!isArray(constants)) {
constants = arguments;
}
var result = {};
var i = -1;
var len = constants.length;
Expand Down
32 changes: 31 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
'use strict';

var test = require('tape');
var konst = require('..');
var konst;

test('argument slice when Array.isArray does not exist', function(t) {
t.plan(1);

// Store the real isArray to reassign it back to Array later.
var isArray = Array.isArray;

// Make isArray null before requiring konst.
Array.isArray = null;
konst = require('..');
t.looseEqual(konst('FOO', 'BAR', 'BAZ'), {
FOO: 'FOO',
BAR: 'BAR',
BAZ: 'BAZ'
});

// Reassign isArray back to Array so that the rest of the tests can continue
// under the assumption that isArray exists.
Array.isArray = isArray;
});

test('empty array', function(t) {
t.plan(1);
Expand All @@ -16,3 +36,13 @@ test('non-empty array', function(t) {
BAZ: 'BAZ'
});
});

test('argument slice', function(t) {
t.plan(1);
t.looseEqual(konst('FOO', 'BAR', 'BAZ'), {
FOO: 'FOO',
BAR: 'BAR',
BAZ: 'BAZ'
});
});

0 comments on commit db67694

Please sign in to comment.