File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
src/rsg-components/Preview Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,13 @@ export default class Preview extends Component {
62
62
}
63
63
}
64
64
65
+ componentWillUnmount ( ) {
66
+ if ( ! this . mountNode ) {
67
+ return ;
68
+ }
69
+ ReactDOM . unmountComponentAtNode ( this . mountNode ) ;
70
+ }
71
+
65
72
executeCode ( ) {
66
73
this . setState ( {
67
74
error : null ,
Original file line number Diff line number Diff line change @@ -11,6 +11,30 @@ const options = {
11
11
} ,
12
12
} ;
13
13
14
+ it ( 'should unmount Wrapper when Preview unmounts and mountNodeMock is not null' , ( ) => {
15
+ const actual = mount ( < Preview code = { code } evalInContext = { ( ) => noop } /> , options ) ;
16
+ actual . instance ( ) . mountNode = { hi : 1 } ;
17
+ const ReactDOM = require ( 'react-dom' ) ;
18
+ const unmountComponentAtNodeMock = jest . fn ( ) ;
19
+ ReactDOM . unmountComponentAtNode = unmountComponentAtNodeMock ;
20
+
21
+ actual . unmount ( ) ;
22
+
23
+ expect ( unmountComponentAtNodeMock ) . toBeCalled ( ) ;
24
+ } ) ;
25
+
26
+ it ( 'should not unmount Wrapper when Preview unmounts and mountNodeMock is null' , ( ) => {
27
+ const actual = mount ( < Preview code = { code } evalInContext = { ( ) => noop } /> , options ) ;
28
+ actual . instance ( ) . mountNode = null ;
29
+ const ReactDOM = require ( 'react-dom' ) ;
30
+ const unmountComponentAtNodeMock = jest . fn ( ) ;
31
+ ReactDOM . unmountComponentAtNode = unmountComponentAtNodeMock ;
32
+
33
+ actual . unmount ( ) ;
34
+
35
+ expect ( unmountComponentAtNodeMock ) . not . toBeCalled ( ) ;
36
+ } ) ;
37
+
14
38
it ( 'should render component renderer' , ( ) => {
15
39
const actual = shallow ( < Preview code = { code } evalInContext = { noop } /> , options ) ;
16
40
You can’t perform that action at this time.
0 commit comments