我怎样才能告诉 Jasmine 间谍只听我告诉它期待的消息而忽略任何其他消息?
例如:
示例组
describe 'View', ->
describe 'render', ->
beforeEach ->
@view = new View
@view.el = jasmine.createSpyObj 'el', ['append']
@view.render()
it 'appends the first entry to the list', ->
expect(@view.el.append).toHaveBeenCalledWith '<li>First</li>'
it 'appends the second entry to the list', ->
expect(@view.el.append).toHaveBeenCalledWith '<li>Second</li>'
执行
class View
render: ->
@el.append '<li>First</li>', '<li>Second</li>'
输出
View
render
appends the first entry to the list
Expected spy el.append to have been called \
with [ '<li>First</li>' ] but was called \
with [ [ '<li>First</li>', '<li>Second</li>' ] ]
appends the second entry to the list
Expected spy el.append to have been called \
with [ '<li>Second</li>' ] but was called \
with [ [ '<li>First</li>', '<li>Second</li>' ] ]