【问题标题】:Jasmine spyOn working where sinon does not?Jasmine spyOn 在诗侬没有的地方工作?
【发布时间】:2012-06-24 08:08:02
【问题描述】:

只是在做一些js测试,一直在尝试使用sinon。我有以下测试,我想在其中存根 draw 和 draw_association 函数。 jasmine 的 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

【问题讨论】:

    标签: coffeescript jasmine sinon


    【解决方案1】:

    我误解了 sinon.spy 的作用。它只是观察该方法,而 jasmine spyOn 将其排除在外。我将上面的内容改为 sinon.stub() 并且它可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-18
      • 1970-01-01
      • 1970-01-01
      • 2018-09-13
      • 1970-01-01
      • 1970-01-01
      • 2019-02-09
      相关资源
      最近更新 更多