Skip to content

Commit

Permalink
fix: flaky float number asserter
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlewind committed Dec 20, 2022
1 parent 4db6e0d commit 294e5b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tests/selection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
assertBlockCount,
assertRichTexts,
assertSelection,
assertAlmostEqual,
} from './utils/asserts';

test('click on blank area', async ({ page }) => {
Expand Down Expand Up @@ -545,10 +546,10 @@ test('selection on heavy page', async ({ page }) => {
const rect = await page
.locator('.affine-page-frame-selection-rect')
.evaluate(element => element.getBoundingClientRect());
expect(rect.x).toBe(first.x - 1);
expect(rect.y).toBe(first.y - 1);
expect(rect.right).toBe(last.x + 1);
expect(rect.bottom).toBe(last.y + 1);
assertAlmostEqual(rect.x, first.x - 1, 1);
assertAlmostEqual(rect.y, first.y - 1, 1);
assertAlmostEqual(rect.right, last.x + 1, 1);
assertAlmostEqual(rect.bottom, last.y + 1, 1);
},
}
);
Expand Down
8 changes: 8 additions & 0 deletions tests/utils/asserts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,11 @@ export async function assertClipItems(page: Page, key: string, value: unknown) {
const actual = clipItems.find(item => item.mimeType === key)?.data;
expect(actual).toEqual(value);
}

export function assertAlmostEqual(
actual: number,
expected: number,
precision = 0.001
) {
expect(Math.abs(actual - expected)).toBeLessThan(precision);
}

1 comment on commit 294e5b3

@vercel
Copy link

@vercel vercel bot commented on 294e5b3 Dec 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.