Skip to content

Commit 9105bb4

Browse files
refactor(testing): refactor sorting report unit tests
1 parent 965bfdc commit 9105bb4

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

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

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,12 @@ describe('sortCategoryAudits', () => {
200200
{ weight: 10, score: 1 },
201201
] as WeighedAuditReport[];
202202
const sortedAudits = [...mockAudits].sort(sortCategoryAudits);
203-
expect(sortedAudits[0]).toEqual(mockAudits[3]);
204-
expect(sortedAudits[1]).toEqual(mockAudits[1]);
205-
expect(sortedAudits[2]).toEqual(mockAudits[0]);
206-
expect(sortedAudits[3]).toEqual(mockAudits[2]);
203+
expect(sortedAudits).toEqual([
204+
{ weight: 10, score: 1 },
205+
{ weight: 5, score: 1 },
206+
{ weight: 0, score: 0.1 },
207+
{ weight: 0, score: 0.7 },
208+
]);
207209
});
208210

209211
it('should sort audits by score and value', () => {
@@ -214,10 +216,12 @@ describe('sortCategoryAudits', () => {
214216
{ score: 0, value: 1 },
215217
] as WeighedAuditReport[];
216218
const sortedAudits = [...mockAudits].sort(sortCategoryAudits);
217-
expect(sortedAudits[0]).toEqual(mockAudits[3]);
218-
expect(sortedAudits[1]).toEqual(mockAudits[0]);
219-
expect(sortedAudits[2]).toEqual(mockAudits[2]);
220-
expect(sortedAudits[3]).toEqual(mockAudits[1]);
219+
expect(sortedAudits).toEqual([
220+
{ score: 0, value: 1 },
221+
{ score: 0.7, value: 1 },
222+
{ score: 0.7, value: 0 },
223+
{ score: 1, value: 1 },
224+
]);
221225
});
222226

223227
it('should sort audits by value and title', () => {
@@ -228,10 +232,12 @@ describe('sortCategoryAudits', () => {
228232
{ value: 1, title: 'd' },
229233
] as WeighedAuditReport[];
230234
const sortedAudits = [...mockAudits].sort(sortCategoryAudits);
231-
expect(sortedAudits[0]).toEqual(mockAudits[0]);
232-
expect(sortedAudits[1]).toEqual(mockAudits[3]);
233-
expect(sortedAudits[2]).toEqual(mockAudits[2]);
234-
expect(sortedAudits[3]).toEqual(mockAudits[1]);
235+
expect(sortedAudits).toEqual([
236+
{ value: 1, title: 'c' },
237+
{ value: 1, title: 'd' },
238+
{ value: 0, title: 'a' },
239+
{ value: 0, title: 'b' },
240+
]);
235241
});
236242
});
237243

@@ -244,10 +250,12 @@ describe('sortAudits', () => {
244250
{ score: 0, value: 1 },
245251
] as EnrichedAuditReport[];
246252
const sortedAudits = [...mockAudits].sort(sortAudits);
247-
expect(sortedAudits[0]).toEqual(mockAudits[3]);
248-
expect(sortedAudits[1]).toEqual(mockAudits[0]);
249-
expect(sortedAudits[2]).toEqual(mockAudits[2]);
250-
expect(sortedAudits[3]).toEqual(mockAudits[1]);
253+
expect(sortedAudits).toEqual([
254+
{ score: 0, value: 1 },
255+
{ score: 0.7, value: 1 },
256+
{ score: 0.7, value: 0 },
257+
{ score: 1, value: 1 },
258+
]);
251259
});
252260

253261
it('should sort audits by value and title', () => {
@@ -258,10 +266,12 @@ describe('sortAudits', () => {
258266
{ value: 1, title: 'd' },
259267
] as EnrichedAuditReport[];
260268
const sortedAudits = [...mockAudits].sort(sortAudits);
261-
expect(sortedAudits[0]).toEqual(mockAudits[0]);
262-
expect(sortedAudits[1]).toEqual(mockAudits[3]);
263-
expect(sortedAudits[2]).toEqual(mockAudits[2]);
264-
expect(sortedAudits[3]).toEqual(mockAudits[1]);
269+
expect(sortedAudits).toEqual([
270+
{ value: 1, title: 'c' },
271+
{ value: 1, title: 'd' },
272+
{ value: 0, title: 'a' },
273+
{ value: 0, title: 'b' },
274+
]);
265275
});
266276
});
267277

0 commit comments

Comments
 (0)