2012-11-02 32 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