All files / src/jest-serializer AngularHTMLSerializer.js

100% Statements 13/13
100% Branches 4/4
100% Functions 2/2
100% Lines 12/12

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 27 28 29  658x   658x   172x 124x   48x 48x 48x   172x           172x 172x     6257x   658x        
/* eslint-disable no-undef */
const prettier = require('prettier');
 
const print = val => {
  let source;
  if (val.getAttribute('ng-version')) {
    source = val.innerHTML;
  } else {
    const tmp = document.createElement('div');
    tmp.appendChild(val);
    source = tmp.innerHTML;
  }
  source = source
    .replace(/\n/g, '')
    .replace(/<!--.*?-->/g, '')
    .replace(/ng-reflect-klass="[^"]*"/g, '')
    .replace(/ng-reflect-[a-z-]*="\[object Object]"/g, '')
    .replace(/_nghost.*=""/g, '');
  const result = prettier.format(source, { parser: 'html', printWidth: 100 }).replace(/^\s*$/g, '').trim();
  return result || 'N/A';
};
 
const test = val => val instanceof Element;
 
module.exports = {
  print: print,
  test: test,
};