import 'mocha' ; import { expect , ifExitCodeIsOtherThan , logOutput , PickEvent } from '@integration/testing-tools' ; import { AssertionError } from '@serenity-js/core' ; import { ActivityFinished , ActivityStarts , SceneFinished , SceneStarts , SceneTagged , TestRunnerDetected } from '@serenity-js/core/lib/events' ; import { ExecutionFailedWithAssertionError , ExecutionFailedWithError , FeatureTag , Name , ProblemIndication } from '@serenity-js/core/lib/model' ; import { jasmine } from '../src/jasmine' ; describe ( '@serenity-js/jasmine' , function ( ) { this . timeout ( 5000 ) ; describe ( 'recognises a failing scenario that' , ( ) => { it ( 'has an explicit call to fail()' , ( ) => jasmine ( 'examples/failing/marked-as-failing.spec.js' ) . then ( ifExitCodeIsOtherThan ( 1 , logOutput ) ) . then ( res => { expect ( res . exitCode ) . to . equal ( 1 ) ; PickEvent . from ( res . events ) . next ( SceneStarts , event => expect ( event . details . name ) . to . equal ( new Name ( 'A scenario fails when marked as failed' ) ) ) . next ( SceneTagged , event => expect ( event . tag ) . to . equal ( new FeatureTag ( 'Jasmine' ) ) ) . next ( TestRunnerDetected , event => expect ( event . name ) . to . equal ( new Name ( 'Jasmine' ) ) ) . next ( SceneFinished , event => { const outcome = event . outcome as ProblemIndication ; expect ( outcome ) . to . be . instanceOf ( ExecutionFailedWithError ) ; expect ( outcome . error . name ) . to . equal ( 'Error' ) ; expect ( outcome . error . message ) . to . equal ( 'Failed: Something happened' ) ; } ) ; } ) ) ; it ( 'throws an error' , ( ) => jasmine ( 'examples/failing/error-thrown.spec.js' ) . then ( ifExitCodeIsOtherThan ( 1 , logOutput ) ) . then ( res => { expect ( res . exitCode ) . to . equal ( 1 ) ; PickEvent . from ( res . events ) . next ( SceneStarts , event => expect ( event . details . name ) . to . equal ( new Name ( 'A scenario fails when an error is thrown' ) ) ) . next ( SceneTagged , event => expect ( event . tag ) . to . equal ( new FeatureTag ( 'Jasmine' ) ) ) . next ( TestRunnerDetected , event => expect ( event . name ) . to . equal ( new Name ( 'Jasmine' ) ) ) . next ( SceneFinished , event => { const outcome = event . outcome as ProblemIndication ; expect ( outcome ) . to . be . instanceOf ( ExecutionFailedWithError ) ; expect ( outcome . error . name ) . to . equal ( 'Error' ) ; expect ( outcome . error . message ) . to . equal ( 'Something happened' ) ; } ) ; } ) ) ; it ( 'fails because of a failing assertion' , ( ) => jasmine ( 'examples/failing/assertion-fails.spec.js' ) . then ( ifExitCodeIsOtherThan ( 1 , logOutput ) ) . then ( res => { expect ( res . exitCode ) . to . equal ( 1 ) ; PickEvent . from ( res . events ) . next ( SceneStarts , event => expect ( event . details . name ) . to . equal ( new Name ( 'A scenario fails when the assertion fails' ) ) ) . next ( SceneTagged , event => expect ( event . tag ) . to . equal ( new FeatureTag ( 'Jasmine' ) ) ) . next ( TestRunnerDetected , event => expect ( event . name ) . to . equal ( new Name ( 'Jasmine' ) ) ) . next ( SceneFinished , event => { const outcome = event . outcome as ProblemIndication ; expect ( outcome ) . to . be . instanceOf ( ExecutionFailedWithAssertionError ) ; const error = outcome . error as AssertionError ; expect ( error ) . to . be . instanceof ( AssertionError ) ; expect ( error . message ) . to . equal ( 'Expected false to equal true.' ) ; expect ( error . expected ) . to . equal ( true ) ; expect ( error . actual ) . to . equal ( false ) ; expect ( error . cause . message ) . to . equal ( `Expected false to equal true.` ) ; } ) ; } ) ) ; it ( 'has multiple failing assertions, which will be wrapped in individual activities' , ( ) => jasmine ( 'examples/failing/multiple-failures.spec.js' ) . then ( ifExitCodeIsOtherThan ( 1 , logOutput ) ) . then ( res => { expect ( res . exitCode ) . to . equal ( 1 ) ; PickEvent . from ( res . events ) . next ( SceneStarts , event => expect ( event . details . name ) . to . equal ( new Name ( 'A scenario can fail with multiple failures' ) ) ) . next ( SceneTagged , event => expect ( event . tag ) . to . equal ( new FeatureTag ( 'Jasmine' ) ) ) . next ( TestRunnerDetected , event => expect ( event . name ) . to . equal ( new Name ( 'Jasmine' ) ) ) . next ( ActivityStarts , event => expect ( event . details . name ) . to . equal ( new Name ( 'Expectation' ) ) ) . next ( ActivityFinished , event => { const outcome = event . outcome as ProblemIndication ; expect ( outcome ) . to . be . instanceOf ( ExecutionFailedWithError ) ; expect ( outcome . error . message ) . to . equal ( 'Failed: first issue' ) ; } ) . next ( ActivityStarts , event => expect ( event . details . name ) . to . equal ( new Name ( 'Expectation' ) ) ) . next ( ActivityFinished , event => { const outcome = event . outcome as ProblemIndication ; expect ( outcome ) . to . be . instanceOf ( ExecutionFailedWithError ) ; expect ( outcome . error . message ) . to . equal ( 'Failed: second issue' ) ; } ) . next ( ActivityStarts , event => expect ( event . details . name ) . to . equal ( new Name ( 'Expectation' ) ) ) . next ( ActivityFinished , event => { const outcome = event . outcome as ProblemIndication ; expect ( outcome ) . to . be . instanceOf ( ExecutionFailedWithAssertionError ) ; const error = outcome . error as AssertionError ; expect ( error ) . to . be . instanceof ( AssertionError ) ; expect ( error . message ) . to . equal ( 'Expected false to equal true.' ) ; expect ( error . expected ) . to . equal ( true ) ; expect ( error . actual ) . to . equal ( false ) ; expect ( error . cause . message ) . to . equal ( `Expected false to equal true.` ) ; } ) . next ( SceneFinished , event => { const outcome = event . outcome as ProblemIndication ; expect ( outcome ) . to . be . instanceOf ( ExecutionFailedWithError ) ; expect ( outcome . error . name ) . to . equal ( 'Error' ) ; expect ( outcome . error . message ) . to . equal ( 'Failed: first issue' ) ; } ) ; } ) ) ; } ) ; } ) ;