Skip to content

Commit

Permalink
Update utils.tsx (#2488)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Trevino <darthtrevino@users.noreply.github.com>
  • Loading branch information
ildar-icoosoft and darthtrevino authored May 26, 2020
1 parent af84889 commit c452af2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/testing/test-utils/src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Backend, DragDropManager } from 'dnd-core'
import { act } from 'react-dom/test-utils'

interface RefType {
getManager: () => DragDropManager | undefined
getManager: () => DragDropManager | undefined,
getDecoratedComponent<T>(): T
}

/**
Expand All @@ -19,9 +20,11 @@ export function wrapInTestContext(
): any {
const forwardedRefFunc = (props: any, ref: React.Ref<RefType>) => {
const dragDropManager = React.useRef<any>(undefined)
const decoratedComponentRef = React.useRef<any>(undefined)

React.useImperativeHandle(ref, () => ({
getManager: () => dragDropManager.current,
getDecoratedComponent: () => decoratedComponentRef.current
}))

return (
Expand All @@ -32,7 +35,7 @@ export function wrapInTestContext(
return null
}}
</DndContext.Consumer>
<DecoratedComponent {...props} />
<DecoratedComponent ref={decoratedComponentRef} {...props} />
</DndProvider>
)
}
Expand Down

0 comments on commit c452af2

Please sign in to comment.