Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support multiple decorators with ReactTestUtils #1358

Merged
merged 1 commit into from
Nov 9, 2023
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
6 changes: 4 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/emotion/src/withStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const withStyle = decorator(

// added so it can be tested with ReactTestUtils
// more info: https://github.com/facebook/react/issues/13455
WithStyle.originalType = ComposedComponent
WithStyle.originalType = ComposedComponent.originalType || ComposedComponent

// we have to pass these on, because sometimes users
// access propTypes of the component in other components
Expand Down
4 changes: 3 additions & 1 deletion packages/shared-types/src/CommonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@ interface InstUIBaseComponent {
}
export interface InstUIComponent
extends ComponentClass<any, any>,
InstUIBaseComponent {}
InstUIBaseComponent {
originalType?: any
}
3 changes: 2 additions & 1 deletion packages/ui-i18n/src/bidirectional.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ const bidirectional: BidirectionalType = decorator((ComposedComponent) => {

// added so it can be tested with ReactTestUtils
// more info: https://github.com/facebook/react/issues/13455
BidirectionalForwardingRef.originalType = ComposedComponent
BidirectionalForwardingRef.originalType =
(ComposedComponent as any).originalType || ComposedComponent

return BidirectionalForwardingRef
}) as BidirectionalType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ const withDeterministicId = decorator((ComposedComponent: InstUIComponent) => {

// added so it can be tested with ReactTestUtils
// more info: https://github.com/facebook/react/issues/13455
WithDeterministicId.originalType = ComposedComponent
WithDeterministicId.originalType =
ComposedComponent.originalType || ComposedComponent

if (process.env.NODE_ENV !== 'production') {
WithDeterministicId.displayName = `WithDeterministicId(${ComposedComponent.displayName})`
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-text-input/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"@instructure/ui-badge": "8.47.1",
"@instructure/ui-color-utils": "8.47.1",
"@instructure/ui-test-utils": "8.47.1",
"@instructure/ui-themes": "8.47.1"
"@instructure/ui-themes": "8.47.1",
"react-dom": "^18.2.0"
},
"dependencies": {
"@babel/runtime": "^7.23.2",
Expand Down
24 changes: 24 additions & 0 deletions packages/ui-text-input/src/TextInput/__tests__/TextInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/

import React from 'react'
import ReactDOM from 'react-dom'
import ReactTestUtils from 'react-dom/test-utils'
import { expect, mount, stub, within, find } from '@instructure/ui-test-utils'

import { TextInput } from '../index'
Expand All @@ -41,7 +43,29 @@ const contentAfterSVG = (
</svg>
)

class WrapperComponent extends React.Component {
render() {
return (
<div>
<TextInput />
</div>
)
}
}

describe('<TextInput/>', async () => {
it('can be found and tested with ReactTestUtils', async () => {
const rootNode = document.createElement('div')
document.body.appendChild(rootNode)

// eslint-disable-next-line react/no-render-return-value
const rendered = ReactDOM.render(<WrapperComponent />, rootNode)
ReactTestUtils.findRenderedComponentWithType(
rendered as any,
(TextInput as any).originalType
)
})

it('should include a label', async () => {
await mount(<TextInput renderLabel="Name" />)
const label = await find('label')
Expand Down
Loading