How to use the @serenity-js/core/lib/model.ExecutionFailedWithAssertionError function in @serenity-js/core

To help you get started, we’ve selected a few @serenity-js/core 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 / jasmine / src / SerenityReporterForJasmine.ts View on Github external
private failureOutcomeFrom(failure: Expectation): ProblemIndication {
        const error = this.errorFrom(failure);

        if (error instanceof AssertionError) {
            // sadly, Jasmine error propagation mechanism is rather basic
            // and unable to serialise the expected/actual properties of the AssertionError object
            return new ExecutionFailedWithAssertionError(error);
        }

        if (!! failure.matcherName) {                       // the presence of a non-empty matcherName property indicates a Jasmine-specific assertion error
            return new ExecutionFailedWithAssertionError(
                new AssertionError(failure.message, failure.expected, failure.actual, error),
            );
        }

        return new ExecutionFailedWithError(error);
    }
github jan-molak / serenity-js / packages / cucumber / src / listeners / cucumber-0.ts View on Github external
// tslint:disable:switch-default
    switch (true) {
        case status === 'undefined':
            return new ImplementationPending(new ImplementationPendingError('Step not implemented'));

        case status === 'ambiguous':
            if (! error) {
                // Only the step result contains the "ambiguous step def error", the scenario itself doesn't
                return new ExecutionFailedWithError(new AmbiguousStepDefinitionError('Multiple step definitions match'));
            }

            return new ExecutionFailedWithError(error);

        case status === 'failed':
            switch (true) {
                case error instanceof AssertionError:       return new ExecutionFailedWithAssertionError(error as AssertionError);
                case error instanceof TestCompromisedError: return new ExecutionCompromised(error as TestCompromisedError);
                default:                                    return new ExecutionFailedWithError(error);
            }

        case status === 'pending':
            return new ImplementationPending(new ImplementationPendingError('Step not implemented'));

        case status === 'passed':
            return new ExecutionSuccessful();

        case status === 'skipped':
            return new ExecutionSkipped();
    }
    // tslint:enable:switch-default
}
github jan-molak / serenity-js / packages / cucumber / src / listeners / CucumberEventProtocolAdapter.ts View on Github external
outcomeFrom(result: { duration: number, exception: string | Error, status: string }): Outcome {
            const error = !! result.exception && this.errorFrom(result.exception);

            // tslint:disable:switch-default
            switch (result.status) {
                case 'undefined':
                    return new ImplementationPending(new ImplementationPendingError('Step not implemented'));

                case 'ambiguous':
                case 'failed':
                    switch (true) {
                        case error instanceof AssertionError:       return new ExecutionFailedWithAssertionError(error as AssertionError);
                        case error instanceof TestCompromisedError: return new ExecutionCompromised(error as TestCompromisedError);
                        default:                                    return new ExecutionFailedWithError(error);
                    }

                case 'pending':
                    return new ImplementationPending(new ImplementationPendingError('Step not implemented'));

                case 'passed':
                    return new ExecutionSuccessful();

                case 'skipped':
                    return new ExecutionSkipped();
            }
            // tslint:enable:switch-default
        }
github jan-molak / serenity-js / packages / jasmine / src / SerenityReporterForJasmine.ts View on Github external
private failureOutcomeFrom(failure: Expectation): ProblemIndication {
        const error = this.errorFrom(failure);

        if (error instanceof AssertionError) {
            // sadly, Jasmine error propagation mechanism is rather basic
            // and unable to serialise the expected/actual properties of the AssertionError object
            return new ExecutionFailedWithAssertionError(error);
        }

        if (!! failure.matcherName) {                       // the presence of a non-empty matcherName property indicates a Jasmine-specific assertion error
            return new ExecutionFailedWithAssertionError(
                new AssertionError(failure.message, failure.expected, failure.actual, error),
            );
        }

        return new ExecutionFailedWithError(error);
    }
github jan-molak / serenity-js / packages / protractor / spec / stage / crew / photographer / Photographer.spec.ts View on Github external
new SceneStarts(defaultCardScenario),
                new TaskStarts(pickACard),
                new TaskFinished(pickACard, outcome),
                new SceneFinished(defaultCardScenario, outcome),
                new TestRunFinished(),
            ).areSentTo(photographer);

            return stage.waitForNextCue().then(() => {
                expect(recorder.events).to.have.lengthOf(0);
            });
        });

        given(
            { description: 'compromised',               outcome: new ExecutionCompromised(new Error('Database is down'))                                                },
            { description: 'error',                     outcome: new ExecutionFailedWithError(new TypeError())                                                          },
            { description: 'assertion error',           outcome: new ExecutionFailedWithAssertionError(new AssertionError(`expected false to equal true`, false, true)) },
            { description: 'implementation pending',    outcome: new ImplementationPending(new ImplementationPendingError('method missing'))                            },
        ).
        it('does nothing, even when a problem occurs', ({ outcome }) => {
            const { stage, recorder } = create();

            const photographer = new Photographer(new TakePhotosOfFailures(), stage);
            stage.assign(photographer);

            givenFollowingEvents(
                new SceneStarts(defaultCardScenario),
                new SceneFinished(defaultCardScenario, outcome),
                new TestRunFinished(),
            ).areSentTo(photographer);

            return stage.waitForNextCue().then(() => {
                expect(recorder.events).to.have.lengthOf(0);
github jan-molak / serenity-js / packages / serenity-bdd / spec / stage / crew / serenity-bdd-reporter / SerenityBDDReporter.spec.ts View on Github external
it('has failed with an assertion error', () => {

                const assertionError = new AssertionError('expected true to equal false', false, true);

                given(reporter).isNotifiedOfFollowingEvents(
                    new SceneFinished(defaultCardScenario, new ExecutionFailedWithAssertionError(assertionError)),
                    new TestRunFinished(),
                );

                report = stageManager.notifyOf.firstCall.lastArg.artifact.map(_ => _);

                expect(report.result).to.equal('FAILURE');
                expect(report.testFailureCause.errorType).to.equal('AssertionError');
                expect(report.testFailureCause.message).to.equal('expected true to equal false');
                expect(report.testFailureCause.stackTrace).to.be.an('array');
            });