Как расширить задачу «Пуск» новыми сценариями

Я только что узнал о 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
}

Мне очень нравится этот синтаксис, и я хотел бы продолжить эту настройку с большим количеством начальных сценариев. Каким будет правильный подход для достижения этой цели?


person Michael    schedule 07.03.2019    source источник


Ответы (1)


Для тех, у кого есть тот же вопрос, вот как я его решил (нашел аналогичную настройку в репозитории 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[]) {                  
    }                                                       
}
person Michael    schedule 09.03.2019