diff --git a/tests/deletecommand.js b/tests/deletecommand.js index a42e335..485e722 100644 --- a/tests/deletecommand.js +++ b/tests/deletecommand.js @@ -40,11 +40,16 @@ describe( 'DeleteCommand', () => { it( 'uses enqueueChanges', () => { setData( doc, '

foo[]bar

' ); - const spy = testUtils.sinon.spy( doc, 'enqueueChanges' ); + doc.enqueueChanges( () => { + editor.execute( 'delete' ); - editor.execute( 'delete' ); + // We expect that command is executed in enqueue changes block. Since we are already in + // an enqueued block, the command execution will be postponed. Hence, no changes. + expect( getData( doc ) ).to.equal( '

foo[]bar

' ); + } ); - expect( spy.calledOnce ).to.be.true; + // After all enqueued changes are done, the command execution is reflected. + expect( getData( doc ) ).to.equal( '

fo[]bar

' ); } ); it( 'locks buffer when executing', () => { diff --git a/tests/inputcommand.js b/tests/inputcommand.js index 9d14dc7..5aa8655 100644 --- a/tests/inputcommand.js +++ b/tests/inputcommand.js @@ -18,7 +18,7 @@ describe( 'InputCommand', () => { testUtils.createSinonSandbox(); - before( () => { + beforeEach( () => { return ModelTestEditor.create() .then( newEditor => { editor = newEditor; @@ -28,20 +28,17 @@ describe( 'InputCommand', () => { editor.commands.add( 'input', inputCommand ); buffer = inputCommand.buffer; + buffer.size = 0; doc.schema.registerItem( 'p', '$block' ); doc.schema.registerItem( 'h1', '$block' ); } ); } ); - after( () => { + afterEach( () => { return editor.destroy(); } ); - beforeEach( () => { - buffer.size = 0; - } ); - describe( 'buffer', () => { it( 'has buffer getter', () => { expect( editor.commands.get( 'input' ).buffer ).to.be.an.instanceof( ChangeBuffer ); @@ -69,13 +66,16 @@ describe( 'InputCommand', () => { it( 'uses enqueueChanges', () => { setData( doc, '

foo[]bar

' ); - const spy = testUtils.sinon.spy( doc, 'enqueueChanges' ); + doc.enqueueChanges( () => { + editor.execute( 'input', { text: 'x' } ); - editor.execute( 'input', { - text: '' + // We expect that command is executed in enqueue changes block. Since we are already in + // an enqueued block, the command execution will be postponed. Hence, no changes. + expect( getData( doc ) ).to.be.equal( '

foo[]bar

' ); } ); - expect( spy.calledOnce ).to.be.true; + // After all enqueued changes are done, the command execution is reflected. + expect( getData( doc ) ).to.be.equal( '

foox[]bar

' ); } ); it( 'should lock and unlock buffer', () => { @@ -202,11 +202,8 @@ describe( 'InputCommand', () => { it( 'only removes content when no text given (with default non-collapsed range)', () => { setData( doc, '

[fo]obar

' ); - const spy = testUtils.sinon.spy( doc, 'enqueueChanges' ); - editor.execute( 'input' ); - expect( spy.callCount ).to.be.equal( 1 ); expect( getData( doc, { selection: true } ) ).to.be.equal( '

[]obar

' ); expect( buffer.size ).to.be.equal( 0 ); } ); @@ -214,11 +211,8 @@ describe( 'InputCommand', () => { it( 'does not change selection and content when no text given (with default collapsed range)', () => { setData( doc, '

fo[]obar

' ); - const spy = testUtils.sinon.spy( doc, 'enqueueChanges' ); - editor.execute( 'input' ); - expect( spy.callCount ).to.be.equal( 1 ); expect( getData( doc, { selection: true } ) ).to.be.equal( '

fo[]obar

' ); expect( buffer.size ).to.be.equal( 0 ); } );