Skip to content

Commit 31723da

Browse files
authored
Avoid NaN percentage passed when nothing ran (#363)
1 parent 075a33b commit 31723da

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99
### Fixed
10+
- Avoid NaN percentage passed when nothing ran ([#363](https://github.com/cucumber/react-components/pull/363))
1011
- Don't render hook steps with no content ([#361](https://github.com/cucumber/react-components/pull/361))
1112

1213
## [22.3.0] - 2024-08-02

src/components/app/ExecutionSummary.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ describe('ExecutionSummary', () => {
102102
[5, 45, '11%'],
103103
[45, 45, '100%'],
104104
[0, 45, '0%'],
105+
[0, 0, '0%'],
105106
]
106107

107108
for (const [passed, total, percentage] of examples) {

src/components/app/ExecutionSummary.stories.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,14 @@ WithCi.args = {
8383
testRunFinished,
8484
meta: metaWithCi,
8585
} as IExecutionSummaryProps
86+
87+
export const NoTestCases = Template.bind({})
88+
NoTestCases.args = {
89+
scenarioCountByStatus: {
90+
...makeEmptyScenarioCountsByStatus(),
91+
},
92+
totalScenarioCount: 0,
93+
testRunStarted,
94+
testRunFinished,
95+
meta: metaMinimal,
96+
}

src/components/app/ExecutionSummary.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ export const ExecutionSummary: React.FunctionComponent<IExecutionSummaryProps> =
4848
const percentagePassed: string =
4949
new Intl.NumberFormat(undefined, {
5050
style: 'percent',
51-
}).format(scenarioCountByStatus[TestStepResultStatus.PASSED] / totalScenarioCount) + ' passed'
51+
}).format(
52+
totalScenarioCount > 0
53+
? scenarioCountByStatus[TestStepResultStatus.PASSED] / totalScenarioCount
54+
: 0
55+
) + ' passed'
5256
const startDate = testRunStarted?.timestamp
5357
? new Date(TimeConversion.timestampToMillisecondsSinceEpoch(testRunStarted.timestamp))
5458
: undefined

0 commit comments

Comments
 (0)