From 4e98dd86d02d4ee169bd94c6a2e5d430830108e6 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 8 Feb 2018 16:00:07 +0200 Subject: [PATCH] Tests for functionName --- test/functionName/functionName.test.js | 19 ++++++++++++++++--- test/testlog | 9 ++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/test/functionName/functionName.test.js b/test/functionName/functionName.test.js index d2a5d41d4..e64a3d3be 100644 --- a/test/functionName/functionName.test.js +++ b/test/functionName/functionName.test.js @@ -1,13 +1,26 @@ const test = require('tape'); -const functionName = require('./functionName.js'); - +//const functionName = require('./functionName.js'); +// Custom override for console.debug to check output. +let output = ''; +const console = {}; +console.debug = (x) => output = x; +// Override for testing +const functionName = fn => (console.debug(fn.name), fn); test('Testing functionName', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof functionName === 'function', 'functionName is a Function'); + functionName(Math.max); + t.equal(output, 'max', 'Works for native functions'); + function fun(x) {return x}; + functionName(fun); + t.equal(output, 'fun', 'Works for functions'); + const fn = x => x; + functionName(fn); + t.equal(output, 'fn', 'Works for arrow functions'); //t.deepEqual(functionName(args..), 'Expected'); //t.equal(functionName(args..), 'Expected'); //t.false(functionName(args..), 'Expected'); //t.throws(functionName(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/testlog b/test/testlog index 2069ec717..c708ccd38 100644 --- a/test/testlog +++ b/test/testlog @@ -1,4 +1,4 @@ -Test log for: Thu Feb 08 2018 15:13:49 GMT+0200 (GTB Standard Time) +Test log for: Thu Feb 08 2018 15:59:54 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 @@ -463,6 +463,9 @@ Test log for: Thu Feb 08 2018 15:13:49 GMT+0200 (GTB Standard Time) Testing functionName √ functionName is a Function + √ Works for native functions + √ Works for functions + √ Works for arrow functions Testing functions @@ -1751,8 +1754,8 @@ Test log for: Thu Feb 08 2018 15:13:49 GMT+0200 (GTB Standard Time) √ Works with multiple promises - total: 849 - passing: 849 + total: 852 + passing: 852 duration: 2.4s