2016-01-11 110 views
1

我在學習nightwatch.js,並且發現大量重複的代碼。例如,如何使nightwatch.js測試更多DRY

// works 

    objects.expect.element('@user').to.be.present 

    objects.expect.element('@user').value.to.match(/\S/) 

    objects.expect.element('@user').value.to.not.equal(username) 

其中明顯重複了objects.expect.element('@user')。在這種情況下,如果我不重複每條線的話,那麼我最終會失敗。

例如,如果不是我在開始以失敗消息中使用

// fails 

    objects.expect.element('@user').to.be.present 

            .value.to.match(/\S/) 

            .value.to.not.equal(username) 

結果,Expected element <#who> to be present not equal: "Ned the Nighthawk" not match: "/\S/" - expected "not present" but got: present

有沒有辦法使這個代碼更幹?

回答

相關問題