/* eslint-env mocha, browser */
/* global proclaim */

it('has correct instance', function () {
	proclaim.isInstanceOf(Array.prototype.findIndex, Function);
});

it('has correct name', function () {
	function nameOf(fn) {
		return Function.prototype.toString.call(fn).match(/function\s*([^\s]*)\s*\(/)[1];
	}
	proclaim.equal(nameOf(Array.prototype.findIndex), 'findIndex');
});

it('has correct argument length', function () {
	proclaim.equal(Array.prototype.findIndex.length, 1);
});

describe('callback', function () {
	it('has correct argument length', function () {
		[0].findIndex(function () {
			proclaim.equal(arguments.length, 3);
		});
	});
});

describe('applies callback correctly with', function () {
	function isPrime(element) {
		var start = 1;

		while (++start <= Math.sqrt(element)) {
			if (element % start < 1) {
				return false;
			}
		}

		return element > 1;
	}

	it('arrays', function () {
		proclaim.equal([4, 6, 7, 12].findIndex(isPrime), 2);
		proclaim.equal([4, 6, 8, 12].findIndex(isPrime), -1);
	});

	it('array-like objects', function () {
		var
		// 4: 13 is not considered as length omits this element
		objectA = { 0: 4, 1: 6, 2: 7, 3: 12, 4: 13, length: 3 },
		objectB = { 0: 4, 1: 6, 2: 8, 3: 12, 4: 13, length: 3 };

		proclaim.equal(Array.prototype.findIndex.call(objectA, isPrime), 2);
		proclaim.equal(Array.prototype.findIndex.call(objectB, isPrime), -1);
	});
});

@@ -16,17 +16,8 @@
 ocha
-, browser
  */%0A
@@ -25,16 +25,17 @@
 * global
+s
  proclai
@@ -48,28 +48,21 @@
 it('
-has correct instance
+is a function
 ', f
@@ -90,18 +90,16 @@
 m.is
-InstanceOf
+Function
 (Arr
@@ -124,18 +124,8 @@
 ndex
-, Function
 );%0A%7D
@@ -144,20 +144,21 @@
 correct 
-name
+arity
 ', funct
@@ -171,116 +171,95 @@
  %7B%0A%09
-function nameOf(fn) %7B%0A%09%09return Function.prototype.toString.call(fn).match(/function%5Cs*(%5B%5E%5Cs%5D*)%5Cs*%5C(/)%5B1%5D;%0A%09%7D
+proclaim.arity(Array.prototype.findIndex, 1);%0A%7D);%0A%0Ait('has correct name', function () %7B
 %0A%09pr
@@ -269,20 +269,15 @@
 aim.
-equal(n
+hasN
 ame
-Of
 (Arr
@@ -298,17 +298,16 @@
 indIndex
-)
 , 'findI
@@ -327,35 +327,25 @@
 it('
-has correct argument length
+is not enumerable
 ', f
@@ -359,37 +359,45 @@
  () %7B%0A%09proclaim.
-equal
+nonEnumerable
 (Array.prototype
@@ -388,33 +388,35 @@
 (Array.prototype
-.
+, '
 findIndex.length
@@ -412,18 +412,9 @@
 ndex
-.length, 1
+'
 );%0A%7D

improve test coverage for Array.prototype.findindex (#1611)