我有一个 node.js 应用程序,使用异步实用程序来打破嵌套回调。
而且我试图在我的茉莉花规格中监视由 async.waterfall 封闭的函数,但总是失败。
以下代码可以重现错误:
async = require 'async'
app = hi: ->
fn = ->
# app.hi() # works
async.waterfall [
(cb) ->
app.hi() # doesn't work
cb null
], (err) ->
describe 'jasmine', ->
beforeEach ->
spyOn app, 'hi'
it 'test async.waterfall', ->
spyOn app, 'hi'
fn()
expect(app.hi).toHaveBeenCalled()
失败消息:
Failures:
1) jasmine test async.waterfall
Message:
Expected spy hi to have been called.
Stacktrace:
Error: Expected spy hi to have been called.
at new jasmine.ExpectationResult (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:114:32)
at null.toHaveBeenCalled (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1235:29)
at null.<anonymous> (/Volumes/ws/prj/litb/crm/tests/job/indexSpecs.coffee:51:29)
at jasmine.Block.execute (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:1064:17)
at jasmine.Queue.next_ (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2096:31)
at jasmine.Queue.start (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2049:8)
at jasmine.Spec.execute (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2376:14)
at jasmine.Queue.next_ (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2096:31)
at jasmine.Queue.start (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2049:8)
at jasmine.Suite.execute (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2521:14)
at jasmine.Queue.next_ (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2096:31)
at onComplete (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2092:18)
at jasmine.Suite.finish (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2478:5)
at null.onComplete (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2522:10)
at jasmine.Queue.next_ (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2106:14)
at onComplete (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2092:18)
at jasmine.Spec.finish (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2350:5)
at null.onComplete (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2377:10)
at jasmine.Queue.next_ (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2106:14)
at null._onTimeout (/Volumes/ws/prj/litb/crm/node_modules/jasmine-node/lib/jasmine-node/jasmine-1.3.1.js:2086:18)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
但如果函数调用(应该是间谍)在瀑布块之外,它就会通过。
我想知道我的代码是否有问题?还是茉莉花或异步不支持?