# All files / src/utils htmlValidationUtil.ts

100% Statements 11/11
100% Branches 1/1
100% Functions 2/2
100% Lines 10/10

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
    195x
    5x

    12x
    12x
    2x
    2x
    1x

    5x
    12x
    12x

     import cheerio from 'cheerio';
    import * as logger from './logger';

    function logWarningForMissingTbody(rootNode: cheerio.Root, path: string) {
      const tables = rootNode('table');
      for (let i = 0; i < tables.length; i += 1) {
        const table = rootNode(tables[i]);
        if (table.find('tbody').length === 0) {
          logger.error(`Invalid HTML in ${path}.\n`
           + 'Table must have a tbody tag. Please correct this to avoid Vue hydration issues.\n');
        }
      }
    }

    export function checkForVueHydrationViolation(content: string, path: string) {
      const $ = cheerio.load(content);
      logWarningForMissingTbody($, path);
    }