@@ -57,34 +57,55 @@ describe('dialog', () => {
5757 expect ( onClose ) . toHaveBeenCalledTimes ( 1 ) ;
5858 } ) ;
5959
60- it ( 'destroy on hide should unmount child components on close' , ( ) => {
61- const wrapper = mount (
62- < Dialog destroyOnClose >
63- < input className = "test-input" />
64- </ Dialog > ,
65- { attachTo : document . body } ,
66- ) ;
60+ describe ( 'destroyOnClose' , ( ) => {
61+ it ( 'default is false' , ( ) => {
62+ const wrapper = mount (
63+ < Dialog visible >
64+ < input className = "test-destroy" />
65+ </ Dialog > ,
66+ { attachTo : document . body } ,
67+ ) ;
6768
68- // Show
69- wrapper . setProps ( { visible : true } ) ;
70- jest . runAllTimers ( ) ;
71- wrapper . update ( ) ;
69+ act ( ( ) => {
70+ wrapper . setProps ( { visible : false } ) ;
71+ jest . runAllTimers ( ) ;
72+ wrapper . update ( ) ;
73+ } ) ;
7274
73- document . getElementsByClassName ( '.test-input' ) . value = 'test' ;
74- expect ( document . getElementsByClassName ( '.test-input' ) . value ) . toBe ( 'test' ) ;
75+ expect ( document . querySelectorAll ( '.test-destroy' ) ) . toHaveLength ( 1 ) ;
7576
76- // Hide
77- wrapper . setProps ( { visible : false } ) ;
78- jest . runAllTimers ( ) ;
79- wrapper . update ( ) ;
77+ wrapper . unmount ( ) ;
78+ } ) ;
8079
81- // Show
82- wrapper . setProps ( { visible : true } ) ;
83- jest . runAllTimers ( ) ;
84- wrapper . update ( ) ;
80+ it ( 'destroy on hide should unmount child components on close' , ( ) => {
81+ const wrapper = mount (
82+ < Dialog destroyOnClose >
83+ < input className = "test-input" />
84+ </ Dialog > ,
85+ { attachTo : document . body } ,
86+ ) ;
8587
86- expect ( document . getElementsByClassName ( '.test-input' ) . value ) . toBeUndefined ( ) ;
87- wrapper . unmount ( ) ;
88+ // Show
89+ wrapper . setProps ( { visible : true } ) ;
90+ jest . runAllTimers ( ) ;
91+ wrapper . update ( ) ;
92+
93+ document . getElementsByClassName ( '.test-input' ) . value = 'test' ;
94+ expect ( document . getElementsByClassName ( '.test-input' ) . value ) . toBe ( 'test' ) ;
95+
96+ // Hide
97+ wrapper . setProps ( { visible : false } ) ;
98+ jest . runAllTimers ( ) ;
99+ wrapper . update ( ) ;
100+
101+ // Show
102+ wrapper . setProps ( { visible : true } ) ;
103+ jest . runAllTimers ( ) ;
104+ wrapper . update ( ) ;
105+
106+ expect ( document . getElementsByClassName ( '.test-input' ) . value ) . toBeUndefined ( ) ;
107+ wrapper . unmount ( ) ;
108+ } ) ;
88109 } ) ;
89110
90111 it ( 'esc to close' , ( ) => {
0 commit comments