How to use the tiny-types.match function in tiny-types

To help you get started, weā€™ve selected a few tiny-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jan-molak / serenity-js / packages / core / src / screenplay / activities / OutcomeMatcher.ts View on Github external
outcomeFor(error: Error | any): ProblemIndication {
        return match(error)
            .when(ImplementationPendingError, _ => new ImplementationPending(error))
            .when(TestCompromisedError, _ => new ExecutionCompromised(error))
            .when(AssertionError, _ => new ExecutionFailedWithAssertionError(error))
            .when(Error, _ => /AssertionError/.test(error.constructor.name) // mocha
                    ? new ExecutionFailedWithAssertionError(error)
                    : new ExecutionFailedWithError(error))
            .else(_ => new ExecutionFailedWithError(error));
    }
}
github jan-molak / serenity-js / packages / protractor / src / stage / Photographer.ts View on Github external
notifyOf(event: DomainEvent): void {
        match(event)
            .when(InteractionFinished,   ({ value, outcome }: InteractionFinished) => {
                // todo: clean up
                if (this.stage.theShowHasStarted() && outcome.isWorseThan(ImplementationPending)) {

                    const id = CorrelationId.create();

                    this.stage.manager.notifyOf(new AsyncOperationAttempted(
                        new Description(`[${ this.constructor.name }] Taking screenshot of '${ value.name.value }'...`),
                        id,
                    ));

                    BrowseTheWeb.as(this.stage.theActorInTheSpotlight()).takeScreenshot()
                        .then(screenshot => {
                            this.stage.manager.notifyOf(new ArtifactGenerated(
                                value.name,
                                Photo.fromBase64(screenshot),
github jan-molak / serenity-js / packages / console-reporter / src / stage / crew / console-reporter / ConsoleReporter.ts View on Github external
notifyOf(event: DomainEvent): void {
        match(event)
            .when(SceneStarts, (e: SceneStarts) => {

                this.firstError = new FirstError();
                this.startTimes.recordStartOf(e);

                // Print scenario header
                this.printer.println(this.theme.separator('-'));
                this.printer.println(e.value.location.path.value, e.value.location.line ? `:${ e.value.location.line }` : '');
                this.printer.println();
                this.printer.println(this.theme.heading(e.value.category.value, ': ', e.value.name.value));
                this.printer.println();

            })
            .when(TaskStarts, (e: TaskStarts) => {

                this.printer.indent();
github jan-molak / serenity-js / packages / core / src / model / tags / Tags.ts View on Github external
public static from(text: string): Tag[] {
        const [ , type, val ] = Tags.Pattern.exec(text);

        return match(type.toLowerCase())
            .when('manual',     _ => [ new ManualTag() ])
            .when(/issues?/,    _ => val.split(',').map(value => new IssueTag(value.trim())))
            .else(value           => [ new ArbitraryTag(value.trim()) ]);
    }
}
github jan-molak / serenity-js / packages / serenity-bdd / src / stage / crew / serenity-bdd-reporter / strategies / SingleSceneReportingStrategy.ts View on Github external
handle(event: DomainEvent, report: SceneReport): SceneReport {
        return match(event)
            .when(SceneStarts,      (e: SceneStarts)      => report.executionStartedAt(e.timestamp))
            .when(ActivityStarts,   (e: ActivityStarts)   => report.activityStarted(e.value, e.timestamp))
            .when(ActivityFinished, (e: ActivityFinished) => report.activityFinished(e.value, e.outcome, e.timestamp))
            .when(SceneFinished,    (e: SceneFinished)    => {
                return report
                    .executionFinishedAt(e.timestamp)
                    .executionFinishedWith(e.value, e.outcome);
            })
            .else(e => super.handle(e, report));
    }
}
github jan-molak / serenity-js / packages / serenity-bdd / src / stage / crew / serenity-bdd-reporter / strategies / SceneSequenceReportingStrategy.ts View on Github external
handle(event: DomainEvent, report: SceneReport): SceneReport {
        return match(event)
            .when(SceneStarts,                      (e: SceneStarts) => {
                return report
                    .activityStarted(this.asActivity(e.value), e.timestamp)
                    .executionStartedAt(e.timestamp);
            })
            .when(SceneTemplateDetected,    (e: SceneTemplateDetected) => {
                return report.withScenarioOutline(e.template);
            })
            .when(SceneParametersDetected,  (e: SceneParametersDetected) => {
                return report.withScenarioParametersOf(e.scenario, e.value);
            })
            .when(ActivityStarts,                   (e: ActivityStarts) => {
                return report.activityStarted(e.value, e.timestamp);
            })
            .when(ActivityFinished,                 (e: ActivityFinished) => {
                return report.activityFinished(e.value, e.outcome, e.timestamp);
github jan-molak / serenity-js / packages / assertions / src / expectations / not.ts View on Github external
.then((outcome: Outcome) =>
                    match, Outcome>(outcome)
                        .when(ExpectationMet, o => new ExpectationNotMet(this.flipped(this.expectation.toString()), o.expected, o.actual))
                        .else(o => new ExpectationMet(this.flipped(this.expectation.toString()), o.expected, o.actual)));
    }
github jan-molak / serenity-js / packages / core / src / model / outcomes.ts View on Github external
    static fromJSON = (o: SerialisedOutcome) => match(o.code)
        .when(ExecutionCompromised.Code,                _ => ExecutionCompromised.fromJSON(o))
        .when(ExecutionFailedWithError.Code,            _ => ExecutionFailedWithError.fromJSON(o))
        .when(ExecutionFailedWithAssertionError.Code,   _ => ExecutionFailedWithAssertionError.fromJSON(o))
        .when(ImplementationPending.Code,               _ => ImplementationPending.fromJSON(o))
        .when(ExecutionSkipped.Code,                    _ => ExecutionSkipped.fromJSON(o))
        .when(ExecutionIgnored.Code,                    _ => ExecutionIgnored.fromJSON(o))
        .when(ExecutionSuccessful.Code,                 _ => ExecutionSuccessful.fromJSON(o))
        .else(_ => { throw new Error(`Outcome could not be deserialised: ${ JSON.stringify(o) }`); }) as Outcome
github jan-molak / serenity-js / examples / calculator-app / src / domain / query-handlers / ResultCalculator.ts View on Github external
        const operatorsAndOperands = events.map(event => match, Operand | Operator>(event)
            .when(OperandEntered, ({ value }: OperandEntered) => value)
            .when(OperatorUsed,   ({ value }: OperatorUsed)   => value)
            .else(_ => void 0),
        ).filter(event => !! event);
github jan-molak / serenity-js / packages / assertions / src / expectations / and.ts View on Github external
previous.then(outcome =>
                        match(outcome)
                            .when(ExpectationNotMet, o => o)
                            .else(_ => current.answeredBy(actor)(actual)),
                ),