0

我有很多测试,如下所示:

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)

每个测试中只有几个不同的值是不同的。我如何编写一个共享函数来干燥重复的位并使其看起来更干净?

我也有相同的测试来测试边距、边框等

请帮忙。

谢谢瑞克

4

1 回答 1

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
于 2012-11-02T15:44:46.227 回答