From a753d3c62a7b8d7335399ccf2662f5cb4be91c73 Mon Sep 17 00:00:00 2001 From: Evgenia Karunus Date: Thu, 3 Sep 2020 04:39:59 +0500 Subject: [PATCH] Make _name() work well with classes Here is the implementation of .functionName in sinon as a reference https://github.com/sinonjs/sinon/blob/c8901e7bdfd95bc34daf509fa3cc56d3100fb206/docs/releases/sinon-1.10.1.js#L446 --- lib/gently/gently.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/gently/gently.js b/lib/gently/gently.js index 75329ba..4338d90 100644 --- a/lib/gently/gently.js +++ b/lib/gently/gently.js @@ -185,11 +185,13 @@ Gently.prototype._stubFn = function(self, obj, method, name, args) { Gently.prototype._name = function(obj, method, stubFn) { if (obj) { - var objectName = obj.toString(); - if (objectName == '[object Object]' && obj.constructor.name) { - objectName = '[' + obj.constructor.name + ']'; + let objectName + if (typeof obj === 'function' && obj.name) { + objectName = obj.name; + } else { + objectName = obj.toString(); } - return (objectName) + '.' + method + '()'; + return objectName + '.' + method + '()'; } if (stubFn.name) {