我有以下两个步骤
When(/^I run a report every (.+) on (.+) at (\d{1,2}:\d{2})/, (every, day, time) => {
console.log('every %s for day %s at %s', every, day, time);
});
When(/^I run a report every (.+) at (\d{1,2}:\d{2})/, (every, time) => {
console.log('every %s at %s', every, time);
});
我试图将on (.+)
的括号设置为类似于(on (.+))?
,但这使参数Sunday之前的参数变为
on Sunday。
如何定义文本为可选,但将原始单词保留为参数?
谢谢on Sunday
为可选项将使您的代码简洁且难以理解。小黄瓜应该很容易阅读。您的步骤定义也应该如此。您还可以使用许多其他代码重用技术,这些技术可让您编写可读的DRY代码。