From c70b1b35dd1a23ef9ceba4f6885a2e1510e3c337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Fri, 14 Jun 2019 10:02:41 +0200 Subject: [PATCH] fix(metadata): don't rely on `instanceof` checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The testing framework Jest creates a new V8 VM for each test file and as a result, it's not possible to rely on `instanceof Function` checks to work - there may be multiple `Function` constructors present. This commit reworks `instanceof Function` check to use `typeof` instead. Signed-off-by: Miroslav Bajtoš --- packages/metadata/src/decorator-factory.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/metadata/src/decorator-factory.ts b/packages/metadata/src/decorator-factory.ts index 08a1cba0c3e7..d64377e22b5f 100644 --- a/packages/metadata/src/decorator-factory.ts +++ b/packages/metadata/src/decorator-factory.ts @@ -157,12 +157,13 @@ export class DecoratorFactory< * @param member - Method name */ static getNumberOfParameters(target: Object, member?: string) { - if (target instanceof Function && !member) { + if (typeof target === 'function' && !member) { // constructor return target.length; } else { // target[member] is a function - return (<{[methodName: string]: Function}>target)[member!].length; + const method = (<{[methodName: string]: Function}>target)[member!]; + return method.length; } }