mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
tests: Add tests for wrapText util (#4495)
This commit is contained in:
parent
63ce5b82d7
commit
38236bc5e0
3 changed files with 149 additions and 1 deletions
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue