/
helpers_spec.ts
102 lines (87 loc) · 2.72 KB
/
helpers_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
import { describe, it } from 'mocha'
import { expect } from 'chai'
import { getAmbiguousStepException, retriesForPickle } from './helpers'
import { getPickleWithTags } from '../../test/gherkin_helpers'
import StepDefinition from '../models/step_definition'
import { buildOptions } from '../../test/runtime_helpers'
describe('Helpers', () => {
describe('getAmbiguousStepException', () => {
it('returns a nicely formatted error', function () {
// Arrange
const stepDefinitions = [
new StepDefinition({
code: undefined,
expression: undefined,
id: '',
options: undefined,
line: 3,
keyword: 'Given',
pattern: 'pattern1',
uri: 'steps1.js',
}),
new StepDefinition({
code: undefined,
expression: undefined,
id: '',
options: undefined,
line: 4,
keyword: 'Given',
pattern: 'longer pattern2',
uri: 'steps2.js',
}),
]
// Act
const result = getAmbiguousStepException(stepDefinitions)
// Assert
expect(result).to.eql(
'Multiple step definitions match:\n' +
' pattern1 - steps1.js:3\n' +
' longer pattern2 - steps2.js:4'
)
})
})
describe('retriesForPickle', () => {
it('returns 0 if options.retry is not set', async () => {
// Arrange
const pickle = await getPickleWithTags([])
const options = buildOptions({})
// Act
const result = retriesForPickle(pickle, options)
// Assert
expect(result).to.eql(0)
})
it('returns options.retry if set and no options.retryTagFilter is specified', async () => {
// Arrange
const pickle = await getPickleWithTags([])
const options = buildOptions({ retry: 1 })
// Act
const result = retriesForPickle(pickle, options)
// Assert
expect(result).to.eql(1)
})
it('returns options.retry is set and the pickle tags match options.retryTagFilter', async () => {
// Arrange
const pickle = await getPickleWithTags(['@retry'])
const options = buildOptions({
retry: 1,
retryTagFilter: '@retry',
})
// Act
const result = retriesForPickle(pickle, options)
// Assert
expect(result).to.eql(1)
})
it('returns 0 if options.retry is set but the pickle tags do not match options.retryTagFilter', async () => {
// Arrange
const pickle = await getPickleWithTags([])
const options = buildOptions({
retry: 1,
retryTagFilter: '@retry',
})
// Act
const result = retriesForPickle(pickle, options)
// Assert
expect(result).to.eql(0)
})
})
})