Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-component-tester

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-component-tester - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

4

index.js

@@ -1,3 +0,3 @@

import ReactTester from './src/index';
const ReactTester = require('./src/index');
export default ReactTester;
module.exports = ReactTester;
{
"name": "react-component-tester",
"version": "0.0.2",
"version": "0.0.3",
"description": "A simple helper to make testing react components with shallow rendering easier",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,6 +0,6 @@

import stampit from 'stampit';
import _ from 'lodash'; // eslint-disable-line id-length
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import sinon from 'sinon';
const stampit = require('stampit');
const _ = require('lodash'); // eslint-disable-line id-length
const React = require('react');
const TestUtils = require('react-addons-test-utils');
const sinon = require('sinon');

@@ -28,9 +28,9 @@ // FLAVOUR COMPONENT

const flavourComponentInit = function({instance}) {
this.style = instance.props.style;
const flavourComponentInit = function(opts) {
this.style = opts.instance.props.style;
};
const flavourComponent = stampit()
.init(flavourComponentInit)
.methods(flavourComponentMethods);
.init(flavourComponentInit)
.methods(flavourComponentMethods);

@@ -43,24 +43,24 @@ // FLAVOUR

const reduceChildren =
function(parentIndx, childMap, child, indx) {
const childIsElement = TestUtils.isElement(child);
function(parentIndx, childMap, child, indx) {
const childIsElement = TestUtils.isElement(child);
if (childIsElement) {
const id = parentIndx >= 0 ? parentIndx + '.' + indx : indx;
childMap[id] = flavourComponent(child);
if (childIsElement) {
const id = parentIndx >= 0 ? parentIndx + '.' + indx : indx;
childMap[id] = flavourComponent(child);
_.assign(
childMap,
convertAndReduce(
child.props.children,
id
)
);
} else {
childMap[indx] = {
value: child,
};
}
_.assign(
childMap,
convertAndReduce(
child.props.children,
id
)
);
} else {
childMap[indx] = {
value: child,
};
}
return childMap;
};
return childMap;
};
/* eslint-enable no-use-before-define */

@@ -70,7 +70,7 @@

return React
.Children
.toArray(children)
.reduce(
reduceChildren.bind(this, parentIndx),
{}
.Children
.toArray(children)
.reduce(
reduceChildren.bind(this, parentIndx),
{}
);

@@ -80,4 +80,4 @@ };

const reduceTypes = function(childMap, typeMap, key) {
const components =
[...(typeMap.get(childMap[key].type) || []), childMap[key]];
const components = (typeMap.get(childMap[key].type) || []).slice(0);
components.push(childMap[key]);

@@ -89,20 +89,20 @@ typeMap.set(childMap[key].type, components);

const flavourInit = function({instance}) {
const output = instance.shallowRenderer.getRenderOutput();
const flavourInit = function(opts) {
const output = opts.instance.shallowRenderer.getRenderOutput();
this.initialState = _.assign({}, instance.shallowRenderer._instance._instance.state);
this.initialState = _.assign({}, opts.instance.shallowRenderer._instance._instance.state);
this.state = _.assign({}, this.initialState);
this.type = output.type;
this.component = flavourComponent(_.assign({}, output, {reactClass: instance.reactClass}));
this.component = flavourComponent(_.assign({}, output, {reactClass: opts.instance.reactClass}));
this.childMap =
convertAndReduce(output.props.children);
convertAndReduce(output.props.children);
this.typeMap =
Object
.keys(this.childMap)
.reduce(
reduceTypes.bind(null, this.childMap),
new Map()
);
Object
.keys(this.childMap)
.reduce(
reduceTypes.bind(null, this.childMap),
new Map()
);

@@ -142,4 +142,4 @@ // console.log('childMap', this.childMap);

const flavour = stampit()
.init(flavourInit)
.methods(flavourMethods);
.init(flavourInit)
.methods(flavourMethods);

@@ -177,6 +177,6 @@ // TESTER

shallowRenderer
.render(React.createElement(
component,
props
));
.render(React.createElement(
component,
props
));

@@ -188,5 +188,5 @@ return shallowRenderer;

return createFlavour(
name,
this.ComponentToUse,
getShallowRenderer(this.ComponentToUse, props)
name,
this.ComponentToUse,
getShallowRenderer(this.ComponentToUse, props)
);

@@ -202,6 +202,6 @@ };

const ReactTester =
stampit()
.init(testerInit)
.methods(testerMethods);
stampit()
.init(testerInit)
.methods(testerMethods);
export default ReactTester;
module.exports = ReactTester;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc