-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
35 additions
and
17 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
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 |
---|---|---|
@@ -1,18 +1,21 @@ | ||
'use strict'; | ||
|
||
var indexOf = require('../implementation'); | ||
var implementation = require('../implementation'); | ||
var callBind = require('call-bind'); | ||
var test = require('tape'); | ||
var hasStrictMode = require('has-strict-mode')(); | ||
|
||
var runTests = require('./tests'); | ||
|
||
test('as a function', function (t) { | ||
t.test('bad array/this value', function (st) { | ||
st['throws'](callBind(indexOf, null, undefined, 'a'), TypeError, 'undefined is not an object'); | ||
st['throws'](callBind(indexOf, null, null, 'a'), TypeError, 'null is not an object'); | ||
t.test('bad receiver', { skip: !hasStrictMode }, function (st) { | ||
/* eslint no-useless-call: 1 */ | ||
st['throws'](function () { implementation.call(undefined, 'a'); }, TypeError, 'undefined is not an object'); | ||
st['throws'](function () { implementation.call(null, 'a'); }, TypeError, 'null is not an object'); | ||
st.end(); | ||
}); | ||
|
||
runTests(callBind(indexOf), t); | ||
runTests(callBind(implementation), 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 |
---|---|---|
@@ -1,18 +1,17 @@ | ||
'use strict'; | ||
|
||
var indexOf = require('..'); | ||
var callBind = require('call-bind'); | ||
var index = 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'](callBind(indexOf, null, undefined, 'a'), TypeError, 'undefined is not an object'); | ||
st['throws'](callBind(indexOf, null, null, 'a'), TypeError, 'null is not an object'); | ||
t.test('bad array', function (st) { | ||
st['throws'](function () { index(undefined, 'a'); }, TypeError, 'undefined is not an object'); | ||
st['throws'](function () { index(null, 'a'); }, TypeError, 'null is not an object'); | ||
st.end(); | ||
}); | ||
|
||
runTests(indexOf, t); | ||
runTests(index, 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
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 |
---|---|---|
@@ -1,14 +1,22 @@ | ||
'use strict'; | ||
|
||
/* | ||
* var canDistinguishSparseFromUndefined = 0 in [undefined]; // IE 6 - 8 have a bug where this returns false. | ||
* var undefinedIfNoSparseBug = canDistinguishSparseFromUndefined ? undefined : { valueOf: function () { return 0; } }; | ||
*/ | ||
// var canDistinguishSparseFromUndefined = 0 in [undefined]; // IE 6 - 8 have a bug where this returns false. | ||
// var undefinedIfNoSparseBug = canDistinguishSparseFromUndefined ? undefined : { valueOf: function () { return 0; } }; | ||
|
||
// eslint-disable-next-line no-sparse-arrays, array-bracket-spacing | ||
var holesExist = !(0 in [, ]); // FF 3 fails this check | ||
|
||
module.exports = function (indexOf, t) { | ||
t.equal(indexOf([], undefined), -1, 'empty array + undefined yields -1'); | ||
t.equal(indexOf([1], 1), 0, 'array + only item yields its index'); | ||
t.equal(indexOf([NaN], NaN), -1, 'array with NaN + NaN yields -1'); | ||
// eslint-disable-next-line no-sparse-arrays | ||
t.equal(indexOf([1, , 3], undefined), -1, 'sparse array + undefined yields -1'); | ||
|
||
t.equal( | ||
indexOf([1, , 3], undefined), // eslint-disable-line no-sparse-arrays | ||
-1, | ||
'sparse array + undefined yields -1', | ||
{ skip: !holesExist } | ||
); | ||
|
||
t.equal([0, 1].indexOf(1, 2), -1, 'Firefox 2 bug'); | ||
}; |