, props)
-
// Create ReactElements from built up props
if (valIsPrimitive || valIsPropsObject) return
diff --git a/test/specs/commonTests/implementsWrapperProp.tsx b/test/specs/commonTests/implementsWrapperProp.tsx
index 9aaaa34f9a..a2feb9a964 100644
--- a/test/specs/commonTests/implementsWrapperProp.tsx
+++ b/test/specs/commonTests/implementsWrapperProp.tsx
@@ -7,14 +7,14 @@ import { ShorthandValue } from 'utils'
export interface ImplementsWrapperPropOptions {
wrapppedComponentSelector: any
- wrappperComponentSelector?: any
+ WrapperComponent?: any
}
const implementsWrapperProp = (
Component: React.ReactType
,
options: ImplementsWrapperPropOptions,
) => {
- const { wrapppedComponentSelector, wrappperComponentSelector = Slot.defaultProps.as } = options
+ const { wrapppedComponentSelector, WrapperComponent = Slot } = options
const wrapperTests = (wrapper: ReactWrapper) => {
expect(wrapper.length).toBeGreaterThan(0)
@@ -23,11 +23,7 @@ const implementsWrapperProp =
(
describe('"wrapper" prop', () => {
it('wraps the component by default', () => {
- wrapperTests(mount().find(wrappperComponentSelector))
- })
-
- it('wraps the component with a custom element', () => {
- wrapperTests(mount(} />).find('span'))
+ wrapperTests(mount().find(WrapperComponent))
})
it('wraps the component with a custom element using "as" prop', () => {
diff --git a/test/specs/components/RadioGroup/RadioGroup-test.tsx b/test/specs/components/RadioGroup/RadioGroup-test.tsx
index b875c59326..bfebdd896d 100644
--- a/test/specs/components/RadioGroup/RadioGroup-test.tsx
+++ b/test/specs/components/RadioGroup/RadioGroup-test.tsx
@@ -60,7 +60,7 @@ describe('RadioGroup', () => {
})
})
- const itemsTest = getItems => {
+ const itemsTest = (getItems: Function, isShorthandApiTest: boolean = true) => {
it('renders children', () => {
const items = mountWithProvider().find('RadioGroupItem')
@@ -101,31 +101,33 @@ describe('RadioGroup', () => {
})
})
- describe('click event handler', () => {
- it('should set the value when item is clicked', () => {
- const checkedValueChanged = jest.fn()
- const wrapper = mountWithProvider(
- ,
- )
- const radioGroupItems = wrapper.find('RadioGroupItem')
+ if (isShorthandApiTest) {
+ describe('click event handler', () => {
+ it('should set "checked" when item is clicked', () => {
+ const checkedValueChanged = jest.fn()
+ const wrapper = mountWithProvider(
+ ,
+ )
+ const radioGroupItems = wrapper.find('RadioGroupItem')
- radioGroupItems
- .at(1)
- .find('div')
- .first()
- .simulate('click')
+ radioGroupItems
+ .at(1)
+ .find('div')
+ .first()
+ .simulate('click')
- const updatedItems = wrapper.find('RadioGroupItem')
+ const updatedItems = wrapper.find('RadioGroupItem')
- expect(updatedItems.at(0).props().checked).toBe(false)
- expect(updatedItems.at(1).props().checked).toBe(true)
+ expect(updatedItems.at(0).props().checked).toBe(false)
+ expect(updatedItems.at(1).props().checked).toBe(true)
- expect(checkedValueChanged).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({ value: 'test-value2' }),
- )
+ expect(checkedValueChanged).toHaveBeenCalledWith(
+ expect.anything(),
+ expect.objectContaining({ value: 'test-value2' }),
+ )
+ })
})
- })
+ }
it('should not call checkedValueChanged when index did not change', () => {
const checkedValueChanged = jest.fn()
@@ -147,21 +149,23 @@ describe('RadioGroup', () => {
expect(checkedValueChanged).not.toHaveBeenCalled()
})
- it('should not set the value when disabled item is clicked', () => {
- const wrapper = mountWithProvider()
- const radioGroupItems = wrapper.find('RadioGroupItem')
+ if (isShorthandApiTest) {
+ it('should not set "checked" when disabled item is clicked', () => {
+ const wrapper = mountWithProvider()
+ const radioGroupItems = wrapper.find('RadioGroupItem')
- radioGroupItems
- .at(1)
- .find('div')
- .first()
- .simulate('click')
+ radioGroupItems
+ .at(1)
+ .find('div')
+ .first()
+ .simulate('click')
- const updatedItems = wrapper.find('RadioGroupItem')
+ const updatedItems = wrapper.find('RadioGroupItem')
- expect(updatedItems.at(0).props().checked).toBe(false)
- expect(updatedItems.at(1).props().checked).toBe(false)
- })
+ expect(updatedItems.at(0).props().checked).toBe(false)
+ expect(updatedItems.at(1).props().checked).toBe(false)
+ })
+ }
describe('keyDown event handler', () => {
const testKeyDown = (testName, items, initialValue, keyCode, expectedValue) => {
@@ -244,6 +248,6 @@ describe('RadioGroup', () => {
})
}
- itemsTest(getChildrenItems)
+ itemsTest(getChildrenItems, false)
})
})
diff --git a/test/specs/lib/factories-test.tsx b/test/specs/lib/factories-test.tsx
index 5b3b22461a..279bce263c 100644
--- a/test/specs/lib/factories-test.tsx
+++ b/test/specs/lib/factories-test.tsx
@@ -10,7 +10,7 @@ import callable from '../../../src/lib/callable'
// Utils
// ----------------------------------------
-type GetShorthandArgs = {
+type ShorthandConfig = {
Component?: React.ReactType
defaultProps?: Props
mappedProp?: string
@@ -31,7 +31,7 @@ const getShorthand = ({
generateKey,
value,
render,
-}: GetShorthandArgs) =>
+}: ShorthandConfig) =>
createShorthand(Component, mappedProp, value, {
defaultProps,
overrideProps,
@@ -42,7 +42,7 @@ const getShorthand = ({
const isValuePrimitive = (value: ShorthandValue) =>
typeof value === 'string' || typeof value === 'number'
-const testCreateShorthand = (shorthandArgs: GetShorthandArgs, expectedResult: ObjectOf) =>
+const testCreateShorthand = (shorthandArgs: ShorthandConfig, expectedResult: ObjectOf) =>
expect(shallow(getShorthand(shorthandArgs)).props()).toEqual(expectedResult)
// ----------------------------------------
@@ -111,7 +111,11 @@ const itMergesClassNames = (
})
}
-const itAppliesProps = (propsSource, expectedProps, shorthandConfig) => {
+const itAppliesProps = (
+ propsSource: string,
+ expectedProps: Props,
+ shorthandConfig: ShorthandConfig,
+) => {
test(`applies props from the ${propsSource} props`, () => {
testCreateShorthand(shorthandConfig, expectedProps)
})
@@ -482,16 +486,6 @@ describe('factories', () => {
testCreateShorthand({ overrideProps, value: testValue }, overrideProps())
})
- test("is called with the user's element's and default props", () => {
- const defaultProps = { 'data-some': 'defaults' }
- const overrideProps = jest.fn(() => ({}))
- const userProps = { 'data-user': 'props' }
- const value =
-
- shallow(getShorthand({ defaultProps, overrideProps, value }))
- expect(overrideProps).toHaveBeenCalledWith({ ...defaultProps, ...userProps })
- })
-
test("is called with the user's props object", () => {
const defaultProps = { 'data-some': 'defaults' }
const overrideProps = jest.fn(() => ({}))
@@ -524,18 +518,21 @@ describe('factories', () => {
describe('from an element', () => {
itReturnsAValidElement()
- itAppliesDefaultProps()
itDoesNotIncludePropsFromMappedProp()
- itMergesClassNames('element', 'user', { value: })
itAppliesProps('element', { foo: 'foo' }, { value: })
- itOverridesDefaultProps(
- 'element',
- { some: 'defaults', overridden: false },
- { some: 'defaults', overridden: true },
- { value: },
- )
- itOverridesDefaultPropsWithFalseyProps('element', {
- value: ,
+
+ test('forwards original element "as is"', () => {
+ testCreateShorthand(
+ {
+ Component: 'p',
+ value: (
+
+ ),
+ defaultProps: { commonProp: 'default', defaultProp: true },
+ overrideProps: { commonProp: 'override', overrideProp: true },
+ },
+ { commonProp: 'originalElement', originalElementProp: true },
+ )
})
})