# All files / src/user-event/utils content-size.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 2/2
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26

    2x
    5x

    2x

     export interface ContentSize {
      width: number;
      height: number;
    }

    /**
     * Simple function for getting mock the size of given text.
     *
     * It works by calculating height based on number of lines and width based on
     * the longest line length. It does not take into account font size, font
     * family, as well as different letter sizes.
     *
     * @param text text to be measure
     * @returns width and height of the text
     */

    export function getTextContentSize(text: string): ContentSize {
      const lines = text.split('\n');
      const maxLineLength = Math.max(...lines.map((line) => line.length));

      return {
        width: maxLineLength * 5,
        height: lines.length * 16,
      };
    }