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.9.0 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.8.2 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.8.1 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.8.0 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.7.3 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.7.2 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.7.1 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.7.0 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.62 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.61 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.60 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.59 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.58 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.57 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.56 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.55 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.54 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.53 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.52 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.51 node_modules/pretty-format/plugins/ReactTestComponent.js