Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit e76bf82

Browse files
committed
addressed Roman's comments
1 parent 40e08f7 commit e76bf82

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/lib/factories.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,18 @@ function createShorthandFromValue(
105105
const valIsNoop = _.isNil(value) || typeof value === 'boolean'
106106
if (valIsNoop && !options.render) return null
107107

108-
// return value as is if it a ReactElement
109-
if (React.isValidElement(value)) {
110-
return value as React.ReactElement<Props>
111-
}
112-
113108
const valIsPrimitive = typeof value === 'string' || typeof value === 'number'
114109
const valIsPropsObject = _.isPlainObject(value)
110+
const valIsReactElement = React.isValidElement(value)
115111

116112
// unhandled type warning
117-
if (process.env.NODE_ENV !== 'production' && !valIsPrimitive && !valIsPropsObject && !valIsNoop) {
113+
if (
114+
process.env.NODE_ENV !== 'production' &&
115+
!valIsPrimitive &&
116+
!valIsPropsObject &&
117+
!valIsReactElement &&
118+
!valIsNoop
119+
) {
118120
console.error(
119121
[
120122
'Shorthand value must be a string|number|object|ReactElements.',
@@ -124,6 +126,11 @@ function createShorthandFromValue(
124126
)
125127
}
126128

129+
// return value 'as is' if it a ReactElement
130+
if (valIsReactElement) {
131+
return value as React.ReactElement<Props>
132+
}
133+
127134
// ----------------------------------------
128135
// Build up props
129136
// ----------------------------------------

test/specs/components/RadioGroup/RadioGroup-test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('RadioGroup', () => {
103103

104104
if (isShorthandApiTest) {
105105
describe('click event handler', () => {
106-
it('should set the value when item is clicked', () => {
106+
it('should set "checked" when item is clicked', () => {
107107
const checkedValueChanged = jest.fn()
108108
const wrapper = mountWithProvider(
109109
<RadioGroup items={getItems()} checkedValueChanged={checkedValueChanged} />,
@@ -150,7 +150,7 @@ describe('RadioGroup', () => {
150150
})
151151

152152
if (isShorthandApiTest) {
153-
it('should not set the value when disabled item is clicked', () => {
153+
it('should not set "checked" when disabled item is clicked', () => {
154154
const wrapper = mountWithProvider(<RadioGroup items={getItems({ disabledItem: 1 })} />)
155155
const radioGroupItems = wrapper.find('RadioGroupItem')
156156

test/specs/lib/factories-test.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,11 +525,13 @@ describe('factories', () => {
525525
testCreateShorthand(
526526
{
527527
Component: 'p',
528-
value: <span {...{ common: 'user', user: true } as any} />,
529-
defaultProps: { common: 'default', default: true },
530-
overrideProps: { common: 'override', override: true },
528+
value: (
529+
<span {...{ commonProp: 'originalElement', originalElementProp: true } as any} />
530+
),
531+
defaultProps: { commonProp: 'default', defaultProp: true },
532+
overrideProps: { commonProp: 'override', overrideProp: true },
531533
},
532-
{ common: 'user', user: true },
534+
{ commonProp: 'originalElement', originalElementProp: true },
533535
)
534536
})
535537
})

0 commit comments

Comments
 (0)