diff --git a/libraries/metrics/test/unit/coffee/timeAsyncMethodTests.coffee b/libraries/metrics/test/unit/coffee/timeAsyncMethodTests.coffee index c606b5f719..7cb8ad7aa5 100644 --- a/libraries/metrics/test/unit/coffee/timeAsyncMethodTests.coffee +++ b/libraries/metrics/test/unit/coffee/timeAsyncMethodTests.coffee @@ -90,8 +90,8 @@ describe 'timeAsyncMethod', -> describe 'when the wrapped function is not using a callback', -> beforeEach -> - @testObject.nextNumber = (n) -> - return n+1 + @realMethod = sinon.stub().returns(42) + @testObject.nextNumber = @realMethod it 'should not throw an error', -> @timeAsyncMethod @testObject, 'nextNumber', 'test.nextNumber' @@ -99,4 +99,11 @@ describe 'timeAsyncMethod', -> @testObject.nextNumber 2 expect(badCall).to.not.throw(Error) + it 'should call the underlying method', -> + @timeAsyncMethod @testObject, 'nextNumber', 'test.nextNumber' + result = @testObject.nextNumber(12) + expect(@realMethod.callCount).to.equal 1 + expect(@realMethod.calledWith(12)).to.equal true + expect(result).to.equal 42 + diff --git a/libraries/metrics/timeAsyncMethod.coffee b/libraries/metrics/timeAsyncMethod.coffee index b90e2b8971..4134086418 100644 --- a/libraries/metrics/timeAsyncMethod.coffee +++ b/libraries/metrics/timeAsyncMethod.coffee @@ -13,7 +13,9 @@ module.exports = (obj, methodName, prefix, logger) -> [firstArgs..., callback] = originalArgs if !callback? || typeof callback != 'function' - logger.log "[Metrics] expected wrapped method '#{methodName}' to be invoked with a callback" + if logger? + logger.log "[Metrics] expected wrapped method '#{methodName}' to be invoked with a callback" + return realMethod.apply this, originalArgs timer = new metrics.Timer(key)