我刚刚学到了关于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
}我真的很喜欢这个语法,并且想继续这个设置,有更多的开始场景。什么才是实现这个目标的正确方法?
发布于 2019-03-09 15:33:57
对于任何有相同问题的人,这是我如何解决它的(在serenity-js代码库中找到了类似的设置):
// 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[]) {
}
}https://stackoverflow.com/questions/55052427
复制相似问题