Skip to content

Commit

Permalink
Tests: Routed errors inside Vue.nextTick() to mocha for better DX.
Browse files Browse the repository at this point in the history
  • Loading branch information
oleq committed Apr 18, 2019
1 parent 9d2c0e9 commit f2bb2ae
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/ckeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ describe( 'CKEditor Component', () => {
} );

it( 'calls editor#create when initializing', done => {
Vue.config.errorHandler = done;

const stub = sandbox.stub( MockEditor, 'create' ).resolves( new MockEditor() );
const { wrapper } = createComponent();

Expand All @@ -42,6 +44,8 @@ describe( 'CKEditor Component', () => {
} );

it( 'calls editor#destroy when destroying', done => {
Vue.config.errorHandler = done;

const stub = sandbox.stub( MockEditor.prototype, 'destroy' ).resolves();
const { wrapper, vm } = createComponent();

Expand All @@ -55,6 +59,8 @@ describe( 'CKEditor Component', () => {
} );

it( 'passes editor promise rejection error to console.error', done => {
Vue.config.errorHandler = done;

const error = new Error( 'Something went wrong.' );
const consoleErrorStub = sandbox.stub( console, 'error' );

Expand All @@ -75,6 +81,8 @@ describe( 'CKEditor Component', () => {
describe( 'properties', () => {
it( '#editor', () => {
it( 'accepts a string', done => {
Vue.config.errorHandler = done;

expect( vm.editor ).to.equal( 'classic' );

Vue.nextTick( () => {
Expand All @@ -85,6 +93,8 @@ describe( 'CKEditor Component', () => {
} );

it( 'accepts an editor constructor', done => {
Vue.config.errorHandler = done;

const { wrapper, vm } = createComponent( {
editor: MockEditor
} );
Expand All @@ -105,6 +115,8 @@ describe( 'CKEditor Component', () => {
} );

it( 'should set the initial data', done => {
Vue.config.errorHandler = done;

const setDataStub = sandbox.stub( MockEditor.prototype, 'setData' );
const { wrapper } = createComponent( {
value: 'foo'
Expand Down Expand Up @@ -141,6 +153,8 @@ describe( 'CKEditor Component', () => {
} );

it( 'should set the initial editor#isReadOnly', done => {
Vue.config.errorHandler = done;

const { wrapper, vm } = createComponent( {
disabled: true
} );
Expand All @@ -159,6 +173,8 @@ describe( 'CKEditor Component', () => {
} );

it( 'should set the initial editor#config', done => {
Vue.config.errorHandler = done;

const { wrapper, vm } = createComponent( {
config: { foo: 'bar' }
} );
Expand All @@ -172,6 +188,8 @@ describe( 'CKEditor Component', () => {
} );

it( '#instance should be defined', done => {
Vue.config.errorHandler = done;

Vue.nextTick( () => {
expect( vm.instance ).to.be.instanceOf( MockEditor );

Expand All @@ -182,6 +200,8 @@ describe( 'CKEditor Component', () => {

describe( 'bindings', () => {
it( '#disabled should control editor#isReadOnly', done => {
Vue.config.errorHandler = done;

const { wrapper, vm } = createComponent( {
disabled: true
} );
Expand All @@ -198,6 +218,8 @@ describe( 'CKEditor Component', () => {
} );

it( '#value should trigger editor#setData', done => {
Vue.config.errorHandler = done;

Vue.nextTick( () => {
const spy = sandbox.spy( vm.instance, 'setData' );

Expand Down Expand Up @@ -225,6 +247,8 @@ describe( 'CKEditor Component', () => {

describe( 'events', () => {
it( 'emits #ready when editor is created', done => {
Vue.config.errorHandler = done;

Vue.nextTick( () => {
expect( wrapper.emitted().ready.length ).to.equal( 1 );
expect( wrapper.emitted().ready[ 0 ] ).to.deep.equal( [ vm.instance ] );
Expand All @@ -234,6 +258,8 @@ describe( 'CKEditor Component', () => {
} );

it( 'emits #destroy when editor is destroyed', done => {
Vue.config.errorHandler = done;

const { wrapper, vm } = createComponent();

Vue.nextTick( () => {
Expand All @@ -247,6 +273,8 @@ describe( 'CKEditor Component', () => {
} );

it( 'emits debounced #input when editor data changes', done => {
Vue.config.errorHandler = done;

sandbox.stub( ModelDocument.prototype, 'on' );
sandbox.stub( MockEditor.prototype, 'getData' ).returns( 'foo' );

Expand Down Expand Up @@ -274,6 +302,8 @@ describe( 'CKEditor Component', () => {
} );

it( 'emits #focus when editor editable is focused', done => {
Vue.config.errorHandler = done;

sandbox.stub( ViewlDocument.prototype, 'on' );

Vue.nextTick( () => {
Expand All @@ -298,6 +328,8 @@ describe( 'CKEditor Component', () => {
} );

it( 'emits #blur when editor editable is focused', done => {
Vue.config.errorHandler = done;

sandbox.stub( ViewlDocument.prototype, 'on' );

Vue.nextTick( () => {
Expand Down

0 comments on commit f2bb2ae

Please sign in to comment.