Skip to content

Commit c279915

Browse files
mcarleiodavidjgoss
andauthored
fix: remove duplications in steps due to empty parameters (#373)
Co-authored-by: David Goss <[email protected]>
1 parent a819407 commit c279915

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
9+
### Fixed
10+
- Remove duplications in steps due to empty parameters ([#373](https://github.com/cucumber/react-components/pull/373))
911

1012
## [22.4.0] - 2025-03-26
1113
### Added

src/components/gherkin/GherkinStep.spec.tsx

+39
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,43 @@ describe('<GherkinStep>', () => {
4848
expect(container).to.contain.text('Given')
4949
expect(container).to.contain.text('the 48 pixies')
5050
})
51+
it('empty parameters are respected correctly', () => {
52+
const step: messages.Step = {
53+
keyword: 'Given',
54+
text: 'the order is placed',
55+
location: { column: 1, line: 1 },
56+
id: '123',
57+
}
58+
59+
class StubCucumberQuery extends CucumberQuery {
60+
public getStepMatchArgumentsLists(): messages.StepMatchArgumentsList[] {
61+
return [
62+
{
63+
stepMatchArguments: [
64+
{
65+
group: {
66+
start: 9,
67+
value: '',
68+
children: [],
69+
},
70+
},
71+
],
72+
},
73+
]
74+
}
75+
}
76+
77+
class StubGherkinQuery extends GherkinQuery {
78+
getPickleStepIds(): string[] {
79+
return ['dummy-id']
80+
}
81+
}
82+
83+
const { container } = render(<GherkinStep step={step} hasExamples={false} />, {
84+
gherkinQuery: new StubGherkinQuery(),
85+
cucumberQuery: new StubCucumberQuery(),
86+
})
87+
88+
expect(container).to.not.contain.text('the orderthe order is placed')
89+
})
5190
})

src/components/gherkin/GherkinStep.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const DefaultRenderer: DefaultComponent<GherkinStepProps> = ({
7777
stepTextElements.push(<HighLight key={`plain-${index}`} text={plain} />)
7878
}
7979
const arg = argument.group.value
80-
if (arg) {
80+
if (arg !== undefined && arg !== null) {
8181
if (arg.length > 0) {
8282
stepTextElements.push(
8383
<Parameter

0 commit comments

Comments
 (0)