首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用新场景扩展Start任务

如何使用新场景扩展Start任务
EN

Stack Overflow用户
提问于 2019-03-08 04:38:15
回答 1查看 31关注 0票数 0

我刚刚学到了关于serenity-js的知识,并且正在尝试。我正在学习本教程,并注意到了以下示例:

代码语言:javascript
复制
james.attemptsTo(
    Start.withAnEmptyTodoList(),
    AddATodoItem.called('Buy some milk')
)

Start的任务

代码语言:javascript
复制
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
}

我真的很喜欢这个语法,并且想继续这个设置,有更多的开始场景。什么才是实现这个目标的正确方法?

EN

回答 1

Stack Overflow用户

发布于 2019-03-09 15:33:57

对于任何有相同问题的人,这是我如何解决它的(在serenity-js代码库中找到了类似的设置):

代码语言:javascript
复制
// 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[]) {                  
    }                                                       
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55052427

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档