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 に答える