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.30 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.29 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.28 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.27 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.26 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.25 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.24 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.23 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.22 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.21 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.20 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.19 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.18 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.17 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.16 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.15 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.14 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.13 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.12 node_modules/pretty-format/plugins/ReactTestComponent.js
isomorfeus-preact-10.6.11 node_modules/pretty-format/plugins/ReactTestComponent.js