Skip to content

Commit

Permalink
tests(shorthand): allow non-strict assert (#1845)
Browse files Browse the repository at this point in the history
* tests(shorthand): allow non-strict assert

* tests(shorthand): allow non-strict assert

* Merge branches 'master' and 'tests/shorthand-strict' of https://github.com/Semantic-Org/Semantic-UI-React into tests/shorthand-strict

# Conflicts:
#	test/specs/commonTests/implementsShorthandProp.js
  • Loading branch information
layershifter authored and levithomason committed Jul 21, 2017
1 parent 292c595 commit 465b936
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
21 changes: 10 additions & 11 deletions src/elements/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@ class Input extends Component {
focus = () => (this.inputRef.focus())

handleChange = (e) => {
const { onChange } = this.props
const value = _.get(e, 'target.value')

onChange(e, { ...this.props, value })
_.invoke(this.props, 'onChange', e, { ...this.props, value })
}

handleChildOverrides = (child, defaultProps) => ({
Expand All @@ -151,20 +150,20 @@ class Input extends Component {
handleInputRef = c => (this.inputRef = c)

partitionProps = () => {
const { disabled, onChange, type } = this.props
const { disabled, type } = this.props

const tabIndex = this.computeTabIndex()
const unhandled = getUnhandledProps(Input, this.props)
const [htmlInputProps, rest] = partitionHTMLInputProps(unhandled)

htmlInputProps.ref = this.handleInputRef
htmlInputProps.type = type

if (disabled) htmlInputProps.disabled = disabled
if (onChange) htmlInputProps.onChange = this.handleChange
if (tabIndex) htmlInputProps.tabIndex = tabIndex

return [htmlInputProps, rest]
return [{
...htmlInputProps,
disabled,
type,
tabIndex,
onChange: this.handleChange,
ref: this.handleInputRef,
}, rest]
}

render() {
Expand Down
9 changes: 6 additions & 3 deletions test/specs/commonTests/implementsShorthandProp.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ const shorthandComponentName = ShorthandComponent => {
* @param {object} options
* @param {string} options.propKey The name of the shorthand prop.
* @param {string|function} options.ShorthandComponent The component that should be rendered from the shorthand value.
* @param {function} options.mapValueToProps A function that maps a primitive value to the Component props
* @param {boolean} [options.alwaysPresent] Whether or not the shorthand exists by default.
* @param {boolean} [options.assertExactMatch] Selects an assertion method, `contain` will be used if true.
* @param {function} options.mapValueToProps A function that maps a primitive value to the Component props.
* @param {Object} [options.requiredProps={}] Props required to render the component.
* @param {Object} [options.shorthandDefaultProps] Default props for the shorthand component.
* @param {Object} [options.shorthandOverrideProps] Override props for the shorthand component.
* @param {boolean} [options.alwaysPresent] Whether or not the shorthand exists by default
*/
export default (Component, options = {}) => {
const {
alwaysPresent,
assertExactMatch = true,
mapValueToProps,
propKey,
ShorthandComponent,
Expand All @@ -35,6 +37,7 @@ export default (Component, options = {}) => {
requiredProps = {},
} = options
const { assertRequired } = helpers('implementsShorthandProp', Component)
const assertMethod = assertExactMatch ? 'contain' : 'containMatchingElement'

describe(`${propKey} shorthand prop (common)`, () => {
assertRequired(Component, 'a `Component`')
Expand All @@ -50,7 +53,7 @@ export default (Component, options = {}) => {
})
const element = createElement(Component, { ...requiredProps, [propKey]: value })

shallow(element).should.contain(shorthandElement)
shallow(element).should[assertMethod](shorthandElement)
}

if (alwaysPresent || Component.defaultProps && Component.defaultProps[propKey]) {
Expand Down
3 changes: 2 additions & 1 deletion test/specs/elements/Input/Input-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('Input', () => {
})
common.implementsHTMLInputProp(Input, {
alwaysPresent: true,
assertExactMatch: false,
shorthandDefaultProps: { type: 'text' },
})

Expand Down Expand Up @@ -227,7 +228,7 @@ describe('Input', () => {

shallow(<Input disabled={false} />)
.find('input')
.should.have.not.prop('disabled')
.should.have.prop('disabled', false)
})
})

Expand Down

0 comments on commit 465b936

Please sign in to comment.