tests: Add tests for wrapText util (#4495)

This commit is contained in:
Aakansha Doshi 2021-12-28 16:52:57 +05:30 committed by GitHub
parent 63ce5b82d7
commit 38236bc5e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 149 additions and 1 deletions

View file

@ -1,4 +1,4 @@
import { getFontString, arrayToMap } from "../utils";
import { getFontString, arrayToMap, isTestEnv } from "../utils";
import {
ExcalidrawBindableElement,
ExcalidrawElement,
@ -200,6 +200,12 @@ const getTextWidth = (text: string, font: FontString) => {
canvas2dContext.font = font;
const metrics = canvas2dContext.measureText(text);
// since in test env the canvas measureText algo
// doesn't measure text and instead just returns number of
// characters hence we assume that each letteris 10px
if (isTestEnv()) {
return metrics.width * 10;
}
return metrics.width;
};