2016-07-27 60 views
0

可以將常見步驟函數映射到多個給定時間語句嗎?黃瓜JS的步驟定義的格式量角器CucumberJS - 將多個黃瓜語句映射到單步函數

this.Given(/^I have the following for a particular test$/, function() { 
     //code for the step 
    }); 

對於BDD(Specflow)的在C#版本中,多個小黃瓜語句可以被綁定到一個單獨的方法。對於例如

[Given(@"I have the following for a particular test")] 
[Given(@"I have also the following for another test")] 
public void GivenIHaveTheFollowingForAParticularTest() 
{ 

} 

有沒有什麼機制可以在CucumberJS中實現呢?

回答

0

是的,你可以使用正則表達式在cucumber.js中做到這一點。例如:

this.Given(/^I have (?:the following for a particular|also the following for another)? test&/, function() { 
    // code for step 
}); 

上面的正則表達式將匹配兩個語句,所以這個步驟定義將被調用。

要測試它看看這裏:http://www.regextester.com/?fam=95418