Skip to content

Commit 9cd8aa8

Browse files
committed
test: add tests to score filter fn
1 parent 0f92d4a commit 9cd8aa8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/utils/src/lib/reports/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {
1717
} from './types.js';
1818

1919
export function scoreFilter<T extends { score: number }>(
20-
options: ScoreFilter | undefined,
20+
options?: ScoreFilter,
2121
) {
2222
const { isScoreListed = () => true } = options ?? {};
2323
return ({ score }: T) => isScoreListed(score);

packages/utils/src/lib/reports/utils.unit.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,24 @@ import {
2626
formatValueChange,
2727
getPluginNameFromSlug,
2828
roundValue,
29+
scoreFilter,
2930
scoreMarker,
3031
severityMarker,
3132
targetScoreIcon,
3233
} from './utils.js';
3334

35+
describe('scoreFilter', () => {
36+
it('should not filter by score if no options are passed', () => {
37+
expect(scoreFilter()({ score: 0 })).toBe(true);
38+
});
39+
40+
it('should filter by score if options are passed', () => {
41+
expect(
42+
scoreFilter({ isScoreListed: score => score === 0.5 })({ score: 0 }),
43+
).toBe(false);
44+
});
45+
});
46+
3447
describe('formatReportScore', () => {
3548
it.each([
3649
[0, '0'],

0 commit comments

Comments
 (0)