| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- /**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- import testUtils from '/tests/core/_utils/utils.js';
- import utilsTestUtils from '/tests/utils/_utils/utils.js';
- import ObesrvableMixin from '/ckeditor5/utils/observablemixin.js';
- import EmitterMixin from '/ckeditor5/utils/emittermixin.js';
- testUtils.createSinonSandbox();
- describe( 'utilsTestUtils.createObserver()', () => {
- let observable, observable2, observer;
- beforeEach( () => {
- observer = utilsTestUtils.createObserver();
- observable = Object.create( ObesrvableMixin );
- observable.set( { foo: 0, bar: 0 } );
- observable2 = Object.create( ObesrvableMixin );
- observable2.set( { foo: 0, bar: 0 } );
- } );
- it( 'should create an observer', () => {
- function Emitter() {}
- Emitter.prototype = EmitterMixin;
- expect( observer ).to.be.instanceof( Emitter );
- expect( observer.observe ).is.a( 'function' );
- expect( observer.stopListening ).is.a( 'function' );
- } );
- describe( 'Observer', () => {
- /* global console:false */
- it( 'logs changes in the observable', () => {
- const spy = testUtils.sinon.stub( console, 'log' );
- observer.observe( 'Some observable', observable );
- observer.observe( 'Some observable 2', observable2 );
- observable.foo = 1;
- expect( spy.callCount ).to.equal( 1 );
- observable.foo = 2;
- observable2.bar = 3;
- expect( spy.callCount ).to.equal( 3 );
- } );
- it( 'logs changes to specified properties', () => {
- const spy = testUtils.sinon.stub( console, 'log' );
- observer.observe( 'Some observable', observable, [ 'foo' ] );
- observable.foo = 1;
- expect( spy.callCount ).to.equal( 1 );
- observable.bar = 1;
- expect( spy.callCount ).to.equal( 1 );
- } );
- it( 'stops listening when asked to do so', () => {
- const spy = testUtils.sinon.stub( console, 'log' );
- observer.observe( 'Some observable', observable );
- observable.foo = 1;
- expect( spy.callCount ).to.equal( 1 );
- observer.stopListening();
- observable.foo = 2;
- expect( spy.callCount ).to.equal( 1 );
- } );
- } );
- } );
|