2012-06-22 97 views
0

只是在做一些js測試,我一直在嘗試使用sinon。我有以下測試,我想要繪製draw和draw_association函數。來自茉莉花的間諜似乎有效,但是當我使用sinon.spy時,事實並非如此。任何想法爲什麼?Jasmine spyOn在哪裏工作,sinon不?

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 

回答

2

我誤解了sinon.spy的功能。它只是觀察了茉莉花spyOn將其剔除的方法。我把上面的代碼切換到了sinon.stub(),它可以工作。