mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
If function is called without callback, apply with original args
This commit is contained in:
parent
fbe19cd97d
commit
1f77cc0fd3
2 changed files with 12 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue