From 6b922d02ea4578a60cbb099c09d5a33f7f0f1885 Mon Sep 17 00:00:00 2001 From: Barney Carroll Date: Wed, 31 Aug 2016 11:51:15 +0100 Subject: [PATCH] Spies reflect wrapped function's name & length --- ospec/ospec.js | 5 +++++ ospec/tests/test-ospec.js | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ospec/ospec.js b/ospec/ospec.js index af0484ef..50b9899e 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -27,6 +27,11 @@ module.exports = new function init() { if (fn) return fn.apply(this, arguments) } + if (fn) + Object.defineProperties(spy, { + length: {value: fn.length}, + name: {value: fn.name} + }) spy.args = [] spy.callCount = 0 return spy diff --git a/ospec/tests/test-ospec.js b/ospec/tests/test-ospec.js index fc40c17f..38ce0438 100644 --- a/ospec/tests/test-ospec.js +++ b/ospec/tests/test-ospec.js @@ -60,6 +60,8 @@ o.spec("ospec", function() { var output = spy.call(state, {children: children}) + o(spy.length).equals(1) + o(spy.name).equals('view') o(spy.callCount).equals(1) o(spy.args.length).equals(1) o(spy.args[0]).deepEquals({children: children})