我刚刚了解了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
}
我真的很喜欢这种语法,并希望继续使用更多的启动场景。做这件事的正确方法是什么?
对于任何有相同问题的人来说,这是我如何解决的(找到了经过Serenity-JS repo的类似设置):
// Start.ts
export class Start {
public static withATodoListContaining = (items: string[]): StartWithATodoListContaining => new StartWithATodoListContaining(items);
}
// StartWithATodoListContaining.ts
export class StartWithATodoListContaining implements Task {
static withATodoListContaining(items: string[]) {
return new StartWithATodoListContaining(items);
}
performAs(actor: PerformsTasks): PromiseLike<void> {
return actor.attemptsTo(
// todo: add each item to the Todo List
);
}
constructor(private items: string[]) {
}
}