@@ -197,10 +197,10 @@ describe( 'Editor', () => {
197197 } ) ;
198198
199199 it ( 'is `destroyed` after editor destroy' , ( ) => {
200- const editor = new Editor ( ) ;
201-
202- return editor . destroy ( ) . then ( ( ) => {
203- expect ( editor . state ) . to . equal ( 'destroyed' ) ;
200+ return Editor . create ( ) . then ( editor => {
201+ return editor . destroy ( ) . then ( ( ) => {
202+ expect ( editor . state ) . to . equal ( 'destroyed' ) ;
203+ } ) ;
204204 } ) ;
205205 } ) ;
206206
@@ -283,33 +283,49 @@ describe( 'Editor', () => {
283283
284284 describe ( 'destroy()' , ( ) => {
285285 it ( 'should fire "destroy"' , ( ) => {
286- const editor = new Editor ( ) ;
287- const spy = sinon . spy ( ) ;
286+ return Editor . create ( ) . then ( editor => {
287+ const spy = sinon . spy ( ) ;
288288
289- editor . on ( 'destroy' , spy ) ;
289+ editor . on ( 'destroy' , spy ) ;
290290
291- return editor . destroy ( ) . then ( ( ) => {
292- expect ( spy . calledOnce ) . to . be . true ;
291+ return editor . destroy ( ) . then ( ( ) => {
292+ expect ( spy . calledOnce ) . to . be . true ;
293+ } ) ;
293294 } ) ;
294295 } ) ;
295296
296297 it ( 'should destroy all components it initialized' , ( ) => {
298+ return Editor . create ( ) . then ( editor => {
299+ const dataDestroySpy = sinon . spy ( editor . data , 'destroy' ) ;
300+ const modelDestroySpy = sinon . spy ( editor . model , 'destroy' ) ;
301+ const editingDestroySpy = sinon . spy ( editor . editing , 'destroy' ) ;
302+ const pluginsDestroySpy = sinon . spy ( editor . plugins , 'destroy' ) ;
303+ const keystrokesDestroySpy = sinon . spy ( editor . keystrokes , 'destroy' ) ;
304+
305+ return editor . destroy ( )
306+ . then ( ( ) => {
307+ sinon . assert . calledOnce ( dataDestroySpy ) ;
308+ sinon . assert . calledOnce ( modelDestroySpy ) ;
309+ sinon . assert . calledOnce ( editingDestroySpy ) ;
310+ sinon . assert . calledOnce ( pluginsDestroySpy ) ;
311+ sinon . assert . calledOnce ( keystrokesDestroySpy ) ;
312+ } ) ;
313+ } ) ;
314+ } ) ;
315+
316+ it ( 'should wait for the full init before destroying' , done => {
317+ const spy = sinon . spy ( ) ;
297318 const editor = new Editor ( ) ;
298319
299- const dataDestroySpy = sinon . spy ( editor . data , 'destroy' ) ;
300- const modelDestroySpy = sinon . spy ( editor . model , 'destroy' ) ;
301- const editingDestroySpy = sinon . spy ( editor . editing , 'destroy' ) ;
302- const pluginsDestroySpy = sinon . spy ( editor . plugins , 'destroy' ) ;
303- const keystrokesDestroySpy = sinon . spy ( editor . keystrokes , 'destroy' ) ;
320+ editor . on ( 'destroy' , ( ) => {
321+ done ( ) ;
322+ } ) ;
304323
305- return editor . destroy ( )
306- . then ( ( ) => {
307- sinon . assert . calledOnce ( dataDestroySpy ) ;
308- sinon . assert . calledOnce ( modelDestroySpy ) ;
309- sinon . assert . calledOnce ( editingDestroySpy ) ;
310- sinon . assert . calledOnce ( pluginsDestroySpy ) ;
311- sinon . assert . calledOnce ( keystrokesDestroySpy ) ;
312- } ) ;
324+ editor . destroy ( ) ;
325+
326+ sinon . assert . notCalled ( spy ) ;
327+
328+ editor . fire ( 'ready' ) ;
313329 } ) ;
314330 } ) ;
315331
0 commit comments