-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,13 @@ | |
], | ||
}], | ||
}, | ||
|
||
"overrides": [ | ||
{ | ||
"files": "**/*.mjs", | ||
"rules": { | ||
"no-restricted-exports": 0, | ||
}, | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
var item = require('..'); | ||
var test = require('tape'); | ||
var runTests = require('./tests'); | ||
|
||
test('as a function', function (t) { | ||
t.test('bad array/this value', function (st) { | ||
st['throws'](item.bind(null, undefined, function () {}), TypeError, 'undefined is not an object'); | ||
st['throws'](item.bind(null, null, function () {}), TypeError, 'null is not an object'); | ||
st.end(); | ||
}); | ||
|
||
runTests(item, t); | ||
|
||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import item from 'array.prototype.item'; | ||
import * as itemModule from 'array.prototype.item'; | ||
import test from 'tape'; | ||
import runTests from './tests.js'; | ||
|
||
test('as a function', (t) => { | ||
t.test('bad array/this value', (st) => { | ||
st.throws(() => item(undefined), TypeError, 'undefined is not an object'); | ||
st.throws(() => item(null), TypeError, 'null is not an object'); | ||
st.end(); | ||
}); | ||
|
||
runTests(item, t); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('named exports', async (t) => { | ||
t.deepEqual( | ||
Object.keys(itemModule).sort(), | ||
['default', 'shim', 'getPolyfill', 'implementation'].sort(), | ||
'has expected named exports' | ||
); | ||
|
||
const { shim, getPolyfill, implementation } = itemModule; | ||
t.equal(await import('array.prototype.item/shim'), shim, 'shim named export matches deep export'); | ||
t.equal(await import('array.prototype.item/implementation'), implementation, 'implementation named export matches deep export'); | ||
t.equal(await import('array.prototype.item/polyfill'), getPolyfill, 'getPolyfill named export matches deep export'); | ||
|
||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
require('../shim')(); | ||
|
||
var test = require('tape'); | ||
var defineProperties = require('define-properties'); | ||
var bind = require('function-bind'); | ||
var isEnumerable = Object.prototype.propertyIsEnumerable; | ||
var functionsHaveNames = require('functions-have-names')(); | ||
var hasStrictMode = require('has-strict-mode')(); | ||
|
||
var runTests = require('./tests'); | ||
|
||
test('shimmed', function (t) { | ||
t.equal(Array.prototype.item.length, 1, 'Array#item has a length of 1'); | ||
t.test('Function name', { skip: !functionsHaveNames }, function (st) { | ||
st.equal(Array.prototype.item.name, 'item', 'Array#item has name "item"'); | ||
st.end(); | ||
}); | ||
|
||
t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) { | ||
et.equal(false, isEnumerable.call(Array.prototype, 'item'), 'Array#item is not enumerable'); | ||
et.end(); | ||
}); | ||
|
||
t.test('bad array/this value', { skip: !hasStrictMode }, function (st) { | ||
st['throws'](function () { return Array.prototype.item.call(undefined, 'a'); }, TypeError, 'undefined is not an object'); | ||
st['throws'](function () { return Array.prototype.item.call(null, 'a'); }, TypeError, 'null is not an object'); | ||
st.end(); | ||
}); | ||
|
||
runTests(bind.call(Function.call, Array.prototype.item), t); | ||
|
||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
module.exports = function (item, t) { | ||
t.test('item', function (st) { | ||
var arr = [1, [2], [3, 4]]; | ||
|
||
st.equal(item(arr, 0), arr[0]); | ||
st.equal(item(arr, -3), arr[0]); | ||
|
||
st.deepEqual(item(arr, 1), arr[1]); | ||
st.deepEqual(item(arr, -2), arr[1]); | ||
|
||
st.deepEqual(item(arr, 2), arr[2]); | ||
st.deepEqual(item(arr, -1), arr[2]); | ||
|
||
st.equal(item(arr, 3), undefined); | ||
st.equal(item(arr, -4), undefined); | ||
|
||
st.equal(item([], 0), undefined); | ||
st.equal(item([], -1), undefined); | ||
|
||
st.end(); | ||
}); | ||
|
||
t.test('sparse arrays', function (st) { | ||
// eslint-disable-next-line no-sparse-arrays | ||
var arr = [, [1]]; | ||
st.equal(item(arr, 0), undefined); | ||
st.equal(item(arr, -2), undefined); | ||
|
||
st.deepEqual(item(arr, 1), [1]); | ||
st.deepEqual(item(arr, -1), [1]); | ||
|
||
st.end(); | ||
}); | ||
}; |