我刚刚了解了 serenity-js,并且正在尝试一下。我正在关注本教程并注意到以下示例:
james.attemptsTo(
Start.withAnEmptyTodoList(),
AddATodoItem.called('Buy some milk')
)
任务Start
:
export class Start implements Task {
static withATodoListContaining(items: string[]) { // static method to improve the readability
return new Start(items);
}
performAs(actor: PerformsTasks): PromiseLike<void> { // required by the Task interface
return actor.attemptsTo( // delegates the work to lower-level tasks
// todo: add each item to the Todo List
);
}
constructor(private items: string[]) { // constructor assigning the list of items
} // to a private field
}
我真的很喜欢这种语法,并希望通过更多起始场景继续此设置。实现这一目标的正确方法是什么?