All files / src/jest-serializer NgrxActionSerializer.js

100% Statements 25/25
100% Branches 21/21
100% Functions 7/7
100% Lines 24/24

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 30 31 32 33 34 35 36 37 38 39 40 41 42658x 327x 49x     278x 48x 230x 5x   579x   278x     658x 219x 327x     658x 319x 319x 76x 243x 219x 219x   319x     658x 6046x     749x   658x        
const serializeValue = v => {
  if (v === undefined) {
    return ' ' + v;
  }
  let stringified;
  if (v instanceof Array) {
    stringified = ' ' + JSON.stringify(v);
  } else if (v.rootIds && v.edges && v.nodes) {
    stringified = ` tree(${Object.keys(v.nodes)})`;
  } else {
    stringified = ' ' + JSON.stringify(v, (_, val) => (val instanceof Array ? [val.length] : val));
  }
  return stringified.length >= 64 ? stringified.substring(0, 61) + '...' : stringified;
};
 
const serializePayload = v =>
  Object.entries(v)
    .map(([key, val]) => `${key}:${serializeValue(val)}`)
    .join('\n');
 
const print = (val, _, indent) => {
  let ret = val.type;
  if (val.type.startsWith('@ngrx/router-store/')) {
    ret += ': ' + (val.payload?.event?.url || val.payload?.routerState?.url);
  } else if (val.payload) {
    const stringified = serializePayload(val.payload);
    ret += ':\n' + indent(stringified);
  }
  return ret;
};
 
const test = val =>
  !!val &&
  typeof val === 'object' &&
  Object.keys(val).includes('type') &&
  Object.keys(val).every(key => ['type', 'payload'].includes(key));
 
module.exports = {
  print: print,
  test: test,
};