2012-11-02 57 views
0

我有很多的測試,如下列:如何幹涸這些試驗與jasmine.js

it "Should call togglePadding if df-padding is checked", -> 
     spyOn(App.columnsSetupBuildingBlockController.content, 'togglePadding') 
     App.view.set("paddingChecked", null) 

     Em.run -> 
      App.view.set("paddingChecked", true) 

     expect(App.columnsSetupBuildingBlockController.content.togglePadding).toHaveBeenCalledWith(true) 

    it "Should call togglePadding if df-padding is unchecked", -> 
     spyOn(App.columnsSetupBuildingBlockController.content, 'togglePadding') 
     App.view.set("paddingChecked", true) 

     Em.run -> 
      App.view.set("paddingChecked", null) 

     expect(App.columnsSetupBuildingBlockController.content.togglePadding).toHaveBeenCalledWith(null) 

只有在每個測試是不同饑荒預警系統不同的值。我怎麼寫一個共享函數來乾燥重複的位,並使它看起來更清潔?

我也有相同的測試邊緣測試,邊界等

請幫助。

感謝 裏克

回答

1

我敢肯定,我很想念你的問題......事情,但是這是我的理解你想要做

setup = (mode = null)-> 
    value1 = mode 
    value2 = if not mode then true else null 
    spyOn(App.columnsSetupBuildingBlockController.content, 'togglePadding') 
    App.view.set("paddingChecked", value1) 

    Em.run -> 
     App.view.set("paddingChecked", value2) 

    expect(App.columnsSetupBuildingBlockController.content.togglePadding).toHaveBeenCalledWith(value2) 

it "Should call togglePadding if df-padding is checked", -> 
    setup null 

it "Should call togglePadding if df-padding is unchecked", -> 
    setup true