2929 */
3030
3131import React from 'react' ;
32- import ReactDOM from 'react-dom' ;
3332import { resetServerContext } from 'react-beautiful-dnd' ;
33+ import { renderTestElement } from '../../test/react_test_utils' ;
3434import html from 'html' ;
3535import { requiredProps } from '../../test/required_props' ;
3636import { OuiDragDropContext , OuiDraggable , OuiDroppable } from './' ;
@@ -45,50 +45,41 @@ function takeSnapshot(element: HTMLElement) {
4545}
4646
4747describe ( 'OuiDraggable' , ( ) => {
48- let appDiv : HTMLElement ;
49-
5048 beforeEach ( ( ) => {
5149 resetServerContext ( ) ; // resets react-beautiful-dnd's internal instance counter which affects snapshots
52- appDiv = document . createElement ( 'div' ) ;
53- document . body . appendChild ( appDiv ) ;
54- } ) ;
55-
56- afterEach ( ( ) => {
57- ReactDOM . unmountComponentAtNode ( appDiv ) ;
58- document . body . removeChild ( appDiv ) ;
5950 } ) ;
6051
6152 test ( 'is rendered' , ( ) => {
6253 const handler = jest . fn ( ) ;
6354
64- ReactDOM . render (
55+ const { container , cleanup } = renderTestElement (
6556 < OuiDragDropContext onDragEnd = { handler } { ...requiredProps } >
6657 < OuiDroppable droppableId = "testDroppable" >
6758 < OuiDraggable draggableId = "testDraggable" index = { 0 } >
6859 { ( ) => < div > Hello</ div > }
6960 </ OuiDraggable >
7061 </ OuiDroppable >
71- </ OuiDragDropContext > ,
72- appDiv
62+ </ OuiDragDropContext >
7363 ) ;
7464
75- expect ( takeSnapshot ( appDiv ) ) . toMatchSnapshot ( ) ;
65+ expect ( takeSnapshot ( container ) ) . toMatchSnapshot ( ) ;
66+ cleanup ( ) ;
7667 } ) ;
7768
7869 test ( 'can be given ReactElement children' , ( ) => {
7970 const handler = jest . fn ( ) ;
8071
81- ReactDOM . render (
72+ const { container , cleanup } = renderTestElement (
8273 < OuiDragDropContext onDragEnd = { handler } { ...requiredProps } >
8374 < OuiDroppable droppableId = "testDroppable" >
8475 < OuiDraggable draggableId = "testDraggable" index = { 0 } >
8576 < div > Hello</ div >
8677 </ OuiDraggable >
8778 </ OuiDroppable >
88- </ OuiDragDropContext > ,
89- appDiv
79+ </ OuiDragDropContext >
9080 ) ;
9181
92- expect ( takeSnapshot ( appDiv ) ) . toMatchSnapshot ( ) ;
82+ expect ( takeSnapshot ( container ) ) . toMatchSnapshot ( ) ;
83+ cleanup ( ) ;
9384 } ) ;
9485} ) ;
0 commit comments