2014-04-25 08:25:59 +00:00
Tests for Array.prototype.findIndex
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
2015-05-19 19:51:46 +00:00
PASS Array.prototype.findIndex.length is 1
PASS Array.prototype.findIndex.name is 'findIndex'
2014-04-25 08:25:59 +00:00
PASS [undefined, 0, null, false, ''].findIndex(passUndefined) is 0
PASS [undefined, 0, null, false, ''].findIndex(passZero) is 1
PASS [undefined, 0, null, false, ''].findIndex(passNull) is 2
PASS [undefined, 0, null, false, ''].findIndex(passFalse) is 3
PASS [undefined, 0, null, false, ''].findIndex(passEmptyString) is 4
PASS [0, null, false, ''].findIndex(passUndefined) is -1
PASS [undefined, 0, false, ''].findIndex(passNull) is -1
PASS [undefined, 0, null, ''].findIndex(passFalse) is -1
PASS [undefined, 0, null, false].findIndex(passEmptyString) is -1
PASS [undefined, null, false, ''].findIndex(passZero) is -1
2015-05-19 19:51:46 +00:00
Array with holes
2015-05-25 03:51:17 +00:00
PASS (new Array(20)).findIndex(passUndefined) is 0
PASS arrayWithHoles.findIndex(passUndefined) is 0
PASS arrayWithHoles.findIndex(passZero) is 1
PASS arrayWithHoles.findIndex(passNull) is 3
PASS arrayWithHoles.findIndex(passFalse) is 5
PASS arrayWithHoles.findIndex(passEmptyString) is 7
PASS arrayWithHoles.findIndex(passUndefined) is 2
2015-05-19 19:51:46 +00:00
Generic Object
2014-04-25 08:25:59 +00:00
PASS toObject([undefined, 0, null, false, '']).findIndex(passUndefined) is 0
PASS toObject([undefined, 0, null, false, '']).findIndex(passZero) is 1
PASS toObject([undefined, 0, null, false, '']).findIndex(passNull) is 2
PASS toObject([undefined, 0, null, false, '']).findIndex(passFalse) is 3
PASS toObject([undefined, 0, null, false, '']).findIndex(passEmptyString) is 4
PASS toObject([0, null, false, '']).findIndex(passUndefined) is -1
PASS toObject([undefined, 0, false, '']).findIndex(passNull) is -1
PASS toObject([undefined, 0, null, '']).findIndex(passFalse) is -1
PASS toObject([undefined, 0, null, false]).findIndex(passEmptyString) is -1
PASS toObject([undefined, null, false, '']).findIndex(passZero) is -1
2015-05-25 03:51:17 +00:00
PASS toObject(new Array(20)).findIndex(passUndefined) is 0
2015-05-19 19:51:46 +00:00
Array-like object with invalid lengths
PASS var obj = { 0: 1, 1: 2, 2: 3, length: 0 }; Array.prototype.findIndex.call(obj, throwError) is -1
PASS var obj = { 0: 1, 1: 2, 2: 3, length: -0 }; Array.prototype.findIndex.call(obj, throwError) is -1
PASS var obj = { 0: 1, 1: 2, 2: 3, length: -3 }; Array.prototype.findIndex.call(obj, throwError) is -1
Modification during search
2014-04-25 08:25:59 +00:00
PASS [0,1,2,3,4,5,6,7,8,9].findIndex(findItemAddedDuringSearch) is -1
PASS [0,1,2,3,4,5,6,7,8,9].findIndex(findItemRemovedDuringSearch) is -1
2015-05-19 19:51:46 +00:00
Exceptions
2016-07-19 02:45:35 +00:00
PASS Array.prototype.findIndex.call(undefined, function() {}) threw exception TypeError: Array.prototype.findIndex requires that |this| not be null or undefined.
PASS Array.prototype.findIndex.call(null, function() {}) threw exception TypeError: Array.prototype.findIndex requires that |this| not be null or undefined.
2014-04-25 08:25:59 +00:00
PASS [].findIndex(1) threw exception TypeError: Array.prototype.findIndex callback must be a function.
PASS [].findIndex('hello') threw exception TypeError: Array.prototype.findIndex callback must be a function.
PASS [].findIndex([]) threw exception TypeError: Array.prototype.findIndex callback must be a function.
PASS [].findIndex({}) threw exception TypeError: Array.prototype.findIndex callback must be a function.
PASS [].findIndex(null) threw exception TypeError: Array.prototype.findIndex callback must be a function.
PASS [].findIndex(undefined) threw exception TypeError: Array.prototype.findIndex callback must be a function.
2015-05-25 03:51:17 +00:00
Callbacks in the expected order and *not* skipping holes
find callback called with index 0
find callback called with index 1
find callback called with index 2
find callback called with index 3
find callback called with index 4
find callback called with index 5
find callback called with index 6
find callback called with index 7
PASS numberOfCallbacksInFindIndexInArrayWithHoles() is 8
2014-04-25 08:25:59 +00:00
PASS successfullyParsed is true
TEST COMPLETE