Skip to content

Commit 0a80eb4

Browse files
committed
fix tests
1 parent 182cbc9 commit 0a80eb4

7 files changed

Lines changed: 28 additions & 27 deletions

File tree

src/collections/Form/Fields.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import getUnhandledProps from 'src/utils/getUnhandledProps';
55
import numberToWord from 'src/utils/numberToWord';
66
import META from 'src/utils/Meta.js';
77

8-
export default class Field extends Component {
8+
export default class Fields extends Component {
99
static propTypes = {
1010
children: PropTypes.node,
1111
className: PropTypes.string,
@@ -21,13 +21,14 @@ export default class Field extends Component {
2121

2222
render() {
2323
let fieldCount = 0;
24-
Children.forEach(child => {
25-
_.get(child, '_meta.name') === 'Field' && fieldCount++;
24+
Children.forEach(this.props.children, child => {
25+
_.get(child, 'type._meta.name') === 'Field' && fieldCount++;
2626
});
2727
fieldCount = numberToWord(fieldCount);
28+
2829
const classes = classNames(
29-
'sd-field',
30-
{fieldCount: this.props.evenlyDivided},
30+
'sd-fields',
31+
this.props.evenlyDivided && fieldCount,
3132
this.props.className,
3233
'fields'
3334
);

src/elements/Input/Input.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export default class Input extends Component {
88
static propTypes = {
99
children: PropTypes.node,
1010
className: PropTypes.string,
11-
defaultValue: PropTypes.string,
1211
icon: PropTypes.string,
1312
ref: PropTypes.string,
1413
};

src/utils/getUnhandledProps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import _ from 'lodash';
22

33
/**
4-
* Returns an object consisting of props not defined in propTypes nor defaultProps.
4+
* Returns an object consisting of props not defined in propTypes unless defined in defaultProps.
55
* @param {*} instance The `this` keyword in a React Component class.
66
* @returns {{}} A shallow copy of the prop object
77
*/
88
const getUnhandledProps = instance => {
99
return _.omit(instance.props, (val, key) => {
1010
const inPropTypes = _.has(instance.constructor.propTypes, key);
1111
const inDefaultProps = _.has(instance.constructor.defaultProps, key);
12-
return inPropTypes || inDefaultProps;
12+
return inPropTypes && !inDefaultProps;
1313
});
1414
};
1515

test/specs/Conformance-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ describe('Conformance', () => {
8181
const props = {};
8282
// JSX does not render custom html attributes so we prefix them with data-*.
8383
// https://facebook.github.io/react/docs/jsx-gotchas.html#custom-html-attributes
84-
props[`data-${faker.hacker.noun()}`] = faker.hacker.noun();
84+
props[`data-${_.kebabCase(faker.hacker.noun())}`] = faker.hacker.noun();
8585

86+
console.log(props);
8687
// create element with random props
8788
render(<SDComponent {...props} />)
8889
.children()

test/specs/collections/Form/Fields-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import _ from 'lodash';
21
import faker from 'faker';
32
import React from 'react';
43

@@ -15,7 +14,7 @@ describe('Fields', () => {
1514
.findClass('two fields');
1615
});
1716
it('renders children', () => {
18-
const child = faker.hackerPhrase();
17+
const child = faker.hacker.phrase();
1918
render(<Fields>{child}</Fields>)
2019
.findText(child);
2120
});

test/specs/elements/Input/Input-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('Input', () => {
1111
it('has a default value', () => {
1212
render(<Input defaultValue='John' />)
1313
.findTag('input')
14-
.props.defaultValue.should.equal('John');
14+
.value.should.equal('John');
1515
});
1616

1717
it('has a type of phone', () => {

test/utils/getUnhandledPops-test.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@ class TestClass {
1010
}
1111

1212
describe('getUnhandledProps', () => {
13-
it('removes props defined in defaultProps', () => {
14-
TestClass.defaultProps = {imHandled: 'thanks'};
15-
new TestClass()
16-
.unhandledProps
17-
.should.not.have.any.keys(_.keys(TestClass.defaultProps));
18-
});
1913
it('removes props defined in propTypes', () => {
20-
TestClass.propTypes = {imHandled: 'thanks'};
14+
TestClass.propTypes = {removeMe: 'thanks'};
2115
new TestClass()
2216
.unhandledProps
23-
.should.not.have.any.keys(_.keys(TestClass.defaultProps));
17+
.should.not.have.any.keys(_.keys(TestClass.propTypes));
2418
});
25-
it('leave props not in defaultProps || propTypes in tact', () => {
26-
TestClass.defaultProps = {imHandled: 'thanks'};
27-
TestClass.propTypes = {alsoHandled: 'got it'};
28-
const props = {thisShould: 'still be here'};
29-
new TestClass(props)
30-
.unhandledProps
31-
.should.eql(props);
19+
it('leaves props if not defined in propTypes', () => {
20+
const userProps = {leaveThis: 'because it is unhandled'};
21+
TestClass.propTypes = {removeMe: 'because we are handling it'};
22+
const unhandled = new TestClass(userProps).unhandledProps;
23+
24+
unhandled.should.not.have.any.keys(_.keys(TestClass.propTypes));
25+
unhandled.should.have.all.keys(_.keys(userProps));
26+
});
27+
it('leaves propType props if also defined in defaultProps', () => {
28+
TestClass.propTypes = {leaveMe: 'because it is also in defaultProps'};
29+
TestClass.defaultProps = {leaveMe: 'here i am'};
30+
const unhandled = new TestClass().unhandledProps;
31+
32+
unhandled.should.have.all.keys(_.keys(TestClass.defaultProps));
3233
});
3334
});

0 commit comments

Comments
 (0)