Sha256: bfbc5f64c637577e96c52a76c20882115a33bfefd481dd44f31ddf417ea1fc78

Contents?: true

Size: 1.51 KB

Versions: 81

Compression:

Stored size: 1.51 KB

Contents

'use strict';

const printString = require('../printString');

const reactTestInstance = Symbol.for('react.test.json');

function printChildren(children, print, indent, opts) {
  return children.map(child => printInstance(child, print, indent, opts)).join(opts.edgeSpacing);
}

function printProps(props, print, indent, opts) {
  return Object.keys(props).sort().map(name => {
    const prop = props[name];
    let printed = print(prop);

    if (typeof prop !== 'string') {
      if (printed.indexOf('\n') !== -1) {
        printed = '{' + opts.edgeSpacing + indent(indent(printed) + opts.edgeSpacing + '}');
      } else {
        printed = '{' + printed + '}';
      }
    }

    return opts.spacing + indent(name + '=') + printed;
  }).join('');
}

function printInstance(instance, print, indent, opts) {
  if (typeof instance == 'number') {
    return print(instance);
  } else if (typeof instance === 'string') {
    return printString(instance);
  }

  let result = '<' + instance.type;

  if (instance.props) {
    result += printProps(instance.props, print, indent, opts);
  }

  if (instance.children) {
    const children = printChildren(instance.children, print, indent, opts);
    result += '>' + opts.edgeSpacing + indent(children) + opts.edgeSpacing + '</' + instance.type + '>';
  } else {
    result += ' />';
  }

  return result;
}

module.exports = {
  test(object) {
    return object && object.$$typeof === reactTestInstance;
  },
  print(val, print, indent, opts) {
    return printInstance(val, print, indent, opts);
  }
};

Version data entries

81 entries across 81 versions & 1 rubygems

Version Path
isomorfeus-preact-10.6.50 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.49 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.48 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.47 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.46 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.45 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.44 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.43 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.42 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.41 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.40 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.39 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.38 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.37 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.36 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.35 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.34 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.33 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.32 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.31 node_modules/pretty-format/plugins/ReactTestComponent.js