function buildCompareStyleFunction()

in projects/libs/flex-layout/_private-utils/testing/custom-matchers.ts [205:239]


function buildCompareStyleFunction(inlineOnly = true) {
  return function (actual: any, styles: { [k: string]: string } | string, styler: StyleUtils) {
    const found = {};
    const styleMap: {[k: string]: string} = {};

    if (typeof styles === 'string') {
      styleMap[styles] = '';
    } else {
      Object.assign(styleMap, styles);
    }

    let allPassed = Object.keys(styleMap).length !== 0;
    Object.keys(styleMap).forEach(prop => {
      let {elHasStyle, current} = hasPrefixedStyles(actual, prop, styleMap[prop], inlineOnly,
        styler);
      allPassed = allPassed && elHasStyle;
      if (!elHasStyle) {
        extendObject(found, current);
      }
    });

    return {
      pass: allPassed,
      get message() {
        const expectedValueStr = (typeof styles === 'string') ? styleMap :
            JSON.stringify(styleMap, null, 2);
        const foundValueStr = inlineOnly ? actual.outerHTML : JSON.stringify(found);
        return `
          Expected ${foundValueStr}${!allPassed ? '' : ' not'} to contain the
          CSS ${typeof styles === 'string' ? 'property' : 'styles'} '${expectedValueStr}'
        `;
      }
    };
  };
}