Permalink
Browse files

feat(core): anonymous Tasks can be created using \`Task.where(descrip…

…tion, ...sub-tasks)\`

affects: serenity-js

Thanks to @InvictusMB for suggesting the TypeScript trick enabling the \`Task.where\` syntax in #22
  • Loading branch information...
jan-molak committed May 13, 2017
1 parent 6a03291 commit 13f33cc428e762b724ca87183184767a07f59a79
@@ -1,6 +1,6 @@
import sinon = require('sinon');
import expect = require('../../expect');
import { Actor, PerformsTasks, Task, task_where } from '../../../src/serenity/screenplay';
import { Actor, PerformsTasks, Task } from '../../../src/serenity/screenplay';
import { step } from '../../../src/serenity/recording';
import { Journal, StageManager } from '../../../src/serenity/stage/stage_manager';
@@ -88,7 +88,7 @@ describe ('When recording', () => {
describe('minimalist implementation', () => {
const Follow = {
the: (person_of_interest: string) => task_where(`{0} follows the ${person_of_interest}`),
the: (person_of_interest: string) => Task.where(`{0} follows the ${person_of_interest}`),
};
it('notifies the Stage Manager when the activity starts and finishes', () => alice.attemptsTo(Follow.the('white rabbit')).then(() => {
@@ -1,6 +1,8 @@
import { AnswersQuestions, PerformsTasks, UsesAbilities } from './actor';
export abstract class Task implements Activity {
static where = (description: string, ...activities: Activity[]): Task => new AnonymousTask(description, activities);
abstract performAs(actor: PerformsTasks): PromiseLike<void>;
}
@@ -11,3 +13,12 @@ export interface Interaction extends Activity {
export interface Activity {
performAs(actor: PerformsTasks | UsesAbilities | AnswersQuestions): PromiseLike<void>;
}
class AnonymousTask implements Task {
constructor(private description: string, private activities: Activity[]) {
}
performAs = (actor: PerformsTasks) => actor.attemptsTo(...this.activities);
toString = () => this.description;
}

This file was deleted.

Oops, something went wrong.
@@ -1,6 +1,5 @@
export * from './abilities';
export * from './activities';
export * from './actor';
export * from './dsl';
export * from './interactions';
export * from './question';

0 comments on commit 13f33cc

Please sign in to comment.