Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "react"]
}
35 changes: 18 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"build:test": "webpack --config ./tests/webpack.config.test.js",
"build:testrig": "npm run build:test && open ./tests/index.html",
"watch:testrig": "npm run build:test -- --progress --colors --watch",
"test": "istanbul cover _mocha -- --compilers js:babel/register ./tests/**/*tests.js",
"test": "babel-node ./node_modules/istanbul/lib/cli cover _mocha ./tests/**/*tests.js",
"posttest": "npm run lint && cat ./coverage/lcov.info | coveralls",
"test:simple": "mocha ./tests/**/*tests.js --compilers js:babel/register",
"test:spec": "mocha ./tests/stand-alone/link-list/link-list-tests --compilers js:babel/register",
"test:simple": "mocha ./tests/**/*tests.js --compilers js:babel-core/register",
"test:spec": "mocha ./tests/stand-alone/link-list/link-list-tests --compilers js:babel-core/register",
"lint": "eslint ./src ./tests ./index.js"
},
"repository": {
Expand All @@ -37,24 +37,25 @@
},
"homepage": "https://github.com/craigbilner/react-component-tester#readme",
"devDependencies": {
"babel": "5.8.23",
"babel-core": "5.8.25",
"babel-eslint": "4.1.3",
"babel-loader": "5.3.2",
"coveralls": "2.11.4",
"eslint": "1.7.3",
"eslint-config-airbnb": "0.1.0",
"eslint-plugin-react": "3.6.3",
"babel-cli": "6.3.17",
"babel-core": "6.3.26",
"babel-loader": "6.2.0",
"babel-preset-es2015": "6.3.13",
"babel-preset-react": "6.3.13",
"coveralls": "2.11.6",
"eslint": "1.10.3",
"eslint-config-airbnb": "2.1.1",
"eslint-plugin-react": "3.13.0",
"istanbul": "0.4.1",
"mocha": "2.3.3",
"radium": "0.14.3",
"react-dom": "0.14.0",
"webpack": "1.12.2"
"mocha": "2.3.4",
"radium": "0.15.3",
"react-dom": "0.14.3",
"webpack": "1.12.9"
},
"dependencies": {
"lodash": "3.10.1",
"react": "0.14.0",
"react-addons-test-utils": "0.14.0",
"react": "0.14.3",
"react-addons-test-utils": "0.14.3",
"sinon": "1.17.2",
"stampit": "2.1.1"
}
Expand Down
44 changes: 22 additions & 22 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ const doNotSpyOn = {

// METHODS

const propFunc = function(propToTest) {
const propFunc = function (propToTest) {
this.propToTest = propToTest;
return this;
};

const mapsTo = function(method) {
const mapsTo = function (method) {
const symbolToTest = Symbol(method);
this.props[this.propToTest](symbolToTest);

Expand All @@ -36,7 +36,7 @@ const flavourComponentMethods = {
mapsTo,
};

const flavourComponentInit = function(opts) {
const flavourComponentInit = function (opts) {
if (opts.instance.props) {
this.style = opts.instance.props.style;

Expand All @@ -56,12 +56,12 @@ const flavourComponent = stampit()

/* eslint-disable no-use-before-define */
const reduceChildren =
function(parentComponent, reactClass, parentIndx, childMap, child, indx) {
function (parentComponent, reactClass, parentIndx, childMap, child, indx) {
const childIsElement = TestUtils.isElement(child);
const id = parseInt(parentIndx, 10) >= 0 ? parentIndx + '.' + indx : indx;

if (childIsElement) {
childMap[id] = flavourComponent(_.assign({}, child, {parentComponent, reactClass}));
childMap[id] = flavourComponent(_.assign({}, child, { parentComponent, reactClass }));

_.assign(
childMap,
Expand All @@ -82,7 +82,7 @@ const reduceChildren =
};
/* eslint-enable no-use-before-define */

const convertAndReduce = function(parentComponent, reactClass, children, parentIndx) {
const convertAndReduce = function (parentComponent, reactClass, children, parentIndx) {
return React
.Children
.toArray(children)
Expand All @@ -92,7 +92,7 @@ const convertAndReduce = function(parentComponent, reactClass, children, parentI
);
};

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

Expand All @@ -101,12 +101,12 @@ const reduceTypes = function(childMap, typeMap, key) {
return typeMap;
};

const flavourInit = function(opts) {
const flavourInit = function (opts) {
const output = opts.instance.shallowRenderer.getRenderOutput();

this.initialState = _.assign({}, opts.instance.shallowRenderer._instance._instance.state);
this.state = _.assign({}, this.initialState);
this.component = flavourComponent(_.assign({}, output, {reactClass: opts.instance.reactClass}));
this.component = flavourComponent(_.assign({}, output, { reactClass: opts.instance.reactClass }));

if (output) {
if (!output.props) {
Expand All @@ -132,23 +132,23 @@ const flavourInit = function(opts) {
// console.log('typeMap', this.typeMap);
};

const resetState = function() {
const resetState = function () {
this.shallowRenderer._instance._instance.state = _.assign({}, this.initialState);
};

const getState = function() {
const getState = function () {
return this.shallowRenderer._instance._instance.state;
};

const findChild = function(path) {
const findChild = function (path) {
return this.childMap[path];
};

const findComponents = function(component) {
const findComponents = function (component) {
return this.typeMap.get(component) || [];
};

const countComponents = function(component) {
const countComponents = function (component) {
return this.findComponents(component).length;
};

Expand All @@ -167,7 +167,7 @@ const flavour = stampit()
// TESTER

// INIT
const testerInit = function(opts) {
const testerInit = function (opts) {
this.ComponentToUse = null;

this.config = {
Expand All @@ -177,14 +177,14 @@ const testerInit = function(opts) {
};

// METHODS
const restoreSpy = function(method) {
const restoreSpy = function (method) {
if (method.isSinonProxy) {
method.restore();
}
};

const use = function(Component) {
const options = _.merge({}, defaultConfig, this.config, {spyOn: doNotSpyOn});
const use = function (Component) {
const options = _.merge({}, defaultConfig, this.config, { spyOn: doNotSpyOn });

Object.getOwnPropertyNames(Component.prototype).forEach(method => {
if (options.spyOn[method] === false) return;
Expand All @@ -200,15 +200,15 @@ const use = function(Component) {
return this;
};

const createFlavour = function(name, reactClass, shallowRenderer) {
const createFlavour = function (name, reactClass, shallowRenderer) {
return flavour({
name,
reactClass,
shallowRenderer,
});
};

const getShallowRenderer = function(component, props) {
const getShallowRenderer = function (component, props) {
const shallowRenderer = TestUtils.createRenderer();

shallowRenderer
Expand All @@ -220,15 +220,15 @@ const getShallowRenderer = function(component, props) {
return shallowRenderer;
};

const addFlavour = function(name, props) {
const addFlavour = function (name, props) {
return createFlavour(
name,
this.ComponentToUse,
getShallowRenderer(this.ComponentToUse, props)
);
};

const teardown = function() {
const teardown = function () {
const proto = this.ComponentToUse.prototype;

Object.getOwnPropertyNames(proto).forEach(method => {
Expand Down
2 changes: 1 addition & 1 deletion tests/components/address-line/address-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import radium from 'radium';
import styles from './address-line-styles';

export default radium(({text}) => (
export default radium(({ text }) => (
<div style={styles.comp}>
{text}
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/components/address/address.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import AddressLine from '../address-line/address-line';

export default ({address = [], addressee = ''}) => (
export default ({ address = [], addressee = '' }) => (
<div>
<AddressLine text={addressee} />
{
Expand Down
2 changes: 1 addition & 1 deletion tests/components/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default radium(({
signature={signature}
addressee={addressee}
address={address}
/>
/>
</div>
</div>
<div style={styles.gutter}></div>
Expand Down
2 changes: 1 addition & 1 deletion tests/components/message/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import radium from 'radium';
import styles from './message-styles';

export default radium(({text}) => (
export default radium(({ text }) => (
<div style={styles.comp}>
{text}
</div>
Expand Down
10 changes: 5 additions & 5 deletions tests/components/postcard/postcard.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import Signature from '../signature/signature';
import Stamp from '../stamp/stamp-smart';
import Address from '../address/address';

export default radium(({comingFrom, message, signature, address, addressee}) => (
export default radium(({ comingFrom, message, signature, address, addressee }) => (
<div style={styles.comp}>
<div style={styles.left}>
<Welcome
text={comingFrom}
/>
/>
<Message
text={message}
/>
/>

<div style={styles.signatureContainer}>
<Signature
text={signature}
/>
/>
</div>
</div>
<div style={styles.right}>
Expand All @@ -31,7 +31,7 @@ export default radium(({comingFrom, message, signature, address, addressee}) =>
<Address
addressee={addressee}
address={address}
/>
/>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/components/signature/signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import radium from 'radium';
import styles from './signature-styles';

export default radium(({text}) => (
export default radium(({ text }) => (
<div style={styles.comp}>
{text}
</div>
Expand Down
32 changes: 16 additions & 16 deletions tests/components/stamp/stamp-dumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
import React from 'react';
import styles from './stamp-styles';

export default ({types, type, onClick}) => (
export default ({ types, type, onClick }) => (
<div style={styles.comp} onClick={onClick}>
{
(() => {
switch (type) {
case types.NONE:
return (
<div>Place stamp here</div>
);
case types.FIRST_CLASS:
return (
<div>1st</div>
);
case types.SECOND_CLASS:
return (
<div>2nd</div>
case types.NONE:
return (
<div>Place stamp here</div>
);
case types.FIRST_CLASS:
return (
<div>1st</div>
);
case types.SECOND_CLASS:
return (
<div>2nd</div>
);
default:
return (
<div>Unknown stamp</div>
);
default:
return (
<div>Unknown stamp</div>
);
}
})()
}
Expand Down
24 changes: 12 additions & 12 deletions tests/components/stamp/stamp-smart.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ export default class StampSmartComponent extends Component {
let nextType;

switch (currentType) {
case types.NONE:
nextType = types.FIRST_CLASS;
break;
case types.FIRST_CLASS:
nextType = types.SECOND_CLASS;
break;
case types.SECOND_CLASS:
nextType = types.NONE;
break;
default:
nextType = types.NONE;
case types.NONE:
nextType = types.FIRST_CLASS;
break;
case types.FIRST_CLASS:
nextType = types.SECOND_CLASS;
break;
case types.SECOND_CLASS:
nextType = types.NONE;
break;
default:
nextType = types.NONE;
}

return nextType;
Expand All @@ -45,7 +45,7 @@ export default class StampSmartComponent extends Component {
types={stampTypes}
type={this.state.type}
onClick={this.handleOnClick.bind(this)}
/>
/>
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/components/welcome/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import radium from 'radium';
import styles from './welcome-styles';

export default radium(({text}) => (
export default radium(({ text }) => (
<div style={styles.comp}>
{text}
</div>
Expand Down
Loading