From d7cad7f910deb9efacb22750b0df451bf76eaccc Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sat, 3 Feb 2018 12:55:36 +0200 Subject: [PATCH] Tests for findKey, findLastKey, findLast, findLastIndex --- test/findKey/findKey.test.js | 10 +++++++++- test/findLast/findLast.test.js | 3 ++- test/findLastIndex/findLastIndex.test.js | 3 ++- test/findLastKey/findLastKey.test.js | 10 +++++++++- test/testlog | 10 +++++++--- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/test/findKey/findKey.test.js b/test/findKey/findKey.test.js index d4b7870d0..7c505e561 100644 --- a/test/findKey/findKey.test.js +++ b/test/findKey/findKey.test.js @@ -5,9 +5,17 @@ test('Testing findKey', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof findKey === 'function', 'findKey is a Function'); + t.deepEqual(findKey( + { + barney: { age: 36, active: true }, + fred: { age: 40, active: false }, + pebbles: { age: 1, active: true } + }, + o => o['active'] +), 'barney', 'Returns the appropriate key'); //t.deepEqual(findKey(args..), 'Expected'); //t.equal(findKey(args..), 'Expected'); //t.false(findKey(args..), 'Expected'); //t.throws(findKey(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/findLast/findLast.test.js b/test/findLast/findLast.test.js index 6e9ec236d..a2d74405c 100644 --- a/test/findLast/findLast.test.js +++ b/test/findLast/findLast.test.js @@ -5,9 +5,10 @@ test('Testing findLast', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof findLast === 'function', 'findLast is a Function'); + t.equal(findLast([1, 2, 3, 4], n => n % 2 === 1), 3, 'Finds last element for which the given function returns true'); //t.deepEqual(findLast(args..), 'Expected'); //t.equal(findLast(args..), 'Expected'); //t.false(findLast(args..), 'Expected'); //t.throws(findLast(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/findLastIndex/findLastIndex.test.js b/test/findLastIndex/findLastIndex.test.js index 0791336b2..2105f977a 100644 --- a/test/findLastIndex/findLastIndex.test.js +++ b/test/findLastIndex/findLastIndex.test.js @@ -5,9 +5,10 @@ test('Testing findLastIndex', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof findLastIndex === 'function', 'findLastIndex is a Function'); + t.equal(findLastIndex([1, 2, 3, 4], n => n % 2 === 1), 2, 'Finds last index for which the given function returns true'); //t.deepEqual(findLastIndex(args..), 'Expected'); //t.equal(findLastIndex(args..), 'Expected'); //t.false(findLastIndex(args..), 'Expected'); //t.throws(findLastIndex(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/findLastKey/findLastKey.test.js b/test/findLastKey/findLastKey.test.js index f0e99a748..41bcf3624 100644 --- a/test/findLastKey/findLastKey.test.js +++ b/test/findLastKey/findLastKey.test.js @@ -5,9 +5,17 @@ test('Testing findLastKey', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof findLastKey === 'function', 'findLastKey is a Function'); + t.equal(findLastKey( + { + barney: { age: 36, active: true }, + fred: { age: 40, active: false }, + pebbles: { age: 1, active: true } + }, + o => o['active'] +), 'pebbles', 'Returns the appropriate key'); //t.deepEqual(findLastKey(args..), 'Expected'); //t.equal(findLastKey(args..), 'Expected'); //t.false(findLastKey(args..), 'Expected'); //t.throws(findLastKey(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/testlog b/test/testlog index e0e045fc7..2ffb59722 100644 --- a/test/testlog +++ b/test/testlog @@ -1,4 +1,4 @@ -Test log for: Sat Feb 03 2018 12:51:49 GMT+0200 (GTB Standard Time) +Test log for: Sat Feb 03 2018 12:55:18 GMT+0200 (GTB Standard Time) > 30-seconds-of-code@0.0.1 test G:\My Files\git Repositories\30-seconds-of-code > tape test/**/*.test.js | tap-spec @@ -381,18 +381,22 @@ Test log for: Sat Feb 03 2018 12:51:49 GMT+0200 (GTB Standard Time) Testing findKey √ findKey is a Function + √ Returns the appropriate key Testing findLast √ findLast is a Function + √ Finds last element for which the given function returns true Testing findLastIndex √ findLastIndex is a Function + √ Finds last index for which the given function returns true Testing findLastKey √ findLastKey is a Function + √ Returns the appropriate key Testing flatten @@ -1653,8 +1657,8 @@ Test log for: Sat Feb 03 2018 12:51:49 GMT+0200 (GTB Standard Time) √ Works with multiple promises - total: 757 - passing: 757 + total: 761 + passing: 761 duration: 2.4s