/
failing_scenarios.spec.ts
137 lines (118 loc) · 8.17 KB
/
failing_scenarios.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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 { trimmed } from '@serenity-js/core/lib/io';
import { CapabilityTag, ExecutionFailedWithAssertionError, ExecutionFailedWithError, FeatureTag, Name, ProblemIndication, ThemeTag } from '@serenity-js/core/lib/model';
import { describe, it } from 'mocha';
import { jasmine } from '../src/jasmine';
describe('@serenity-js/jasmine', function () {
describe('recognises a failing scenario that', () => {
it('has an explicit call to fail()', () => jasmine('examples/failing/marked-as-failing.spec.js')
.then(ifExitCodeIsOtherThan(3, logOutput))
.then(result => {
expect(result.exitCode).to.equal(3);
PickEvent.from(result.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 ThemeTag('Examples')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('Failing')))
.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: ProblemIndication = 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(3, logOutput))
.then(result => {
expect(result.exitCode).to.equal(3);
PickEvent.from(result.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 ThemeTag('Examples')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('Failing')))
.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: ProblemIndication = 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(3, logOutput))
.then(result => {
expect(result.exitCode).to.equal(3);
PickEvent.from(result.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 ThemeTag('Examples')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('Failing')))
.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(trimmed`
| Expected false to equal true.
|
| Expected boolean: true
| Received boolean: 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(3, logOutput))
.then(result => {
expect(result.exitCode).to.equal(3);
PickEvent.from(result.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 ThemeTag('Examples')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('Failing')))
.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: ProblemIndication = 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.match(new RegExp(trimmed`
| Expected false to equal true.
|
| Expected boolean: true
| Received boolean: false
|
| \\s{4}at .*/examples/failing/multiple-failures.spec.js:5:9
`));
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');
})
;
}));
});
});