正在进行一些js测试,我一直在尝试使用sinon。我有以下测试,我想要绘制draw和draw_association函数。来自茉莉花的spyOn似乎有效,但是当我使用sinon.spy时,却没有。关于为什么的任何想法?
describe "#draw", ->
text = fixture_text()
editor = null
draw_spy = null
draw_associations_spy = null
beforeEach ->
#draw_spy = sinon.spy AwesomeModel.Table.prototype, "draw"
#draw_associations_spy = sinon.spy AwesomeModel.Table.prototype, "draw_associations"
spyOn AwesomeModel.Table.prototype, "draw"
spyOn AwesomeModel.Table.prototype, "draw_associations"
editor = new AwesomeModel.Editor text
editor.parse_table_names()
afterEach ->
#draw_spy.restore()
#draw_associations_spy.restore()
it "unacceptable_coordinates should be the size of the number of tables", ->
editor.draw()
expect(editor.unacceptable_coordinates.length).toEqual editor.tables.length
答案 0 :(得分:2)
我误解了sinon.spy的作用。它只是观察了这个方法,而jasmine spyOn将它存在。我将上面的内容改为sinon.stub()而不是它的工作原理。