Skip to content

Commit

Permalink
Jest: add closeTo() utility temporarily
Browse files Browse the repository at this point in the history
  • Loading branch information
gu-stav committed Jul 27, 2022
1 parent 8907153 commit d886f50
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/core/upload/server/services/__tests__/metrics.js
Expand Up @@ -2,6 +2,11 @@

const metricsService = require('../metrics');

// TODO: the matcher exists in jest@28
const closeTo = (expected, precision = 2) => ({
asymmetricMatch: actual => Math.abs(expected - actual) < Math.pow(10, -precision) / 2,
});

describe('metrics', () => {
describe('computeMetrics', () => {
test.each([
Expand Down Expand Up @@ -96,9 +101,9 @@ describe('metrics', () => {
expect(results).toMatchObject({
assetNumber,
folderNumber,
averageDepth: expect.toBeCloseTo(averageDepth, 3),
averageDepth: closeTo(averageDepth, 3),
maxDepth,
averageDeviationDepth: expect.toBeCloseTo(averageDeviationDepth, 3),
averageDeviationDepth: closeTo(averageDeviationDepth, 3),
});
});
});
Expand Down

0 comments on commit d886f50

Please sign in to comment.