|
|
@@ -7,130 +7,148 @@
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
-bender.amd.require( 'utils' );
|
|
|
+describe( 'extend()', function() {
|
|
|
+ it( 'should extend and override', function( done ) {
|
|
|
+ CKEDITOR.require( [ 'utils' ], function( utils ) {
|
|
|
+ var target = {
|
|
|
+ a: 1,
|
|
|
+ b: 2
|
|
|
+ };
|
|
|
|
|
|
-describe( 'extend()', function( utils ) {
|
|
|
- it( 'should extend and override', function() {
|
|
|
- var target = {
|
|
|
- a: 1,
|
|
|
- b: 2
|
|
|
- };
|
|
|
+ var extensions = {
|
|
|
+ a: 'A',
|
|
|
+ c: 3,
|
|
|
|
|
|
- var extensions = {
|
|
|
- a: 'A',
|
|
|
- c: 3,
|
|
|
+ // Extend by reference (no deep-copy).
|
|
|
+ obj: {
|
|
|
+ a: 1
|
|
|
+ },
|
|
|
|
|
|
- // Extend by reference (no deep-copy).
|
|
|
- obj: {
|
|
|
- a: 1
|
|
|
- },
|
|
|
+ // Extend by reference (no deep-copy).
|
|
|
+ arr: [ 1, 2 ],
|
|
|
|
|
|
- // Extend by reference (no deep-copy).
|
|
|
- arr: [ 1, 2 ],
|
|
|
+ // Extend by reference.
|
|
|
+ fn: function() {}
|
|
|
+ };
|
|
|
|
|
|
- // Extend by reference.
|
|
|
- fn: function() {}
|
|
|
- };
|
|
|
+ var ret = utils.extend( target, extensions );
|
|
|
|
|
|
- var ret = utils.extend( target, extensions );
|
|
|
+ expect( target.a ).to.equal( 'A' );
|
|
|
+ expect( target.b ).to.equal( 2 );
|
|
|
+ expect( target ).to.have.property( 'c' ).to.equal( 3 );
|
|
|
|
|
|
- expect( target.a ).to.equal( 'A' );
|
|
|
- expect( target.b ).to.equal( 2 );
|
|
|
- expect( target ).to.have.property( 'c' ).to.equal( 3 );
|
|
|
+ expect( target ).to.have.property( 'obj' ).to.equal( extensions.obj );
|
|
|
+ expect( target ).to.have.property( 'arr' ).to.equal( extensions.arr );
|
|
|
+ expect( target ).to.have.property( 'fn' ).to.equal( extensions.fn );
|
|
|
|
|
|
- expect( target ).to.have.property( 'obj' ).to.equal( extensions.obj );
|
|
|
- expect( target ).to.have.property( 'arr' ).to.equal( extensions.arr );
|
|
|
- expect( target ).to.have.property( 'fn' ).to.equal( extensions.fn );
|
|
|
+ // "target" should be the return value.
|
|
|
+ expect( ret ).to.equal( target );
|
|
|
|
|
|
- // "target" should be the return value.
|
|
|
- expect( ret ).to.equal( target );
|
|
|
+ done();
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
- it( 'should not be touched by non-objects', function() {
|
|
|
- var target = {
|
|
|
- a: 1
|
|
|
- };
|
|
|
-
|
|
|
- expect( utils.extend( target, function() {} ) ).to.equal( target );
|
|
|
- expect( utils.extend( target, 1 ) ).to.equal( target );
|
|
|
- expect( utils.extend( target, 'a' ) ).to.equal( target );
|
|
|
- expect( utils.extend( target, true ) ).to.equal( target );
|
|
|
- expect( utils.extend( target, undefined ) ).to.equal( target );
|
|
|
- expect( utils.extend( target, [] ) ).to.equal( target );
|
|
|
- expect( utils.extend( target, Date.now() ) ).to.equal( target );
|
|
|
- expect( utils.extend( target ) ).to.equal( target );
|
|
|
-
|
|
|
- // None of the above calls should have touched "target".
|
|
|
- expect( target ).to.have.property( 'a' ).to.equal( 1 );
|
|
|
- expect( Object.getOwnPropertyNames( target ).length ).to.equal( 1 );
|
|
|
+ it( 'should not be touched by non-objects', function( done ) {
|
|
|
+ CKEDITOR.require( [ 'utils' ], function( utils ) {
|
|
|
+ var target = {
|
|
|
+ a: 1
|
|
|
+ };
|
|
|
+
|
|
|
+ expect( utils.extend( target, function() {} ) ).to.equal( target );
|
|
|
+ expect( utils.extend( target, 1 ) ).to.equal( target );
|
|
|
+ expect( utils.extend( target, 'a' ) ).to.equal( target );
|
|
|
+ expect( utils.extend( target, true ) ).to.equal( target );
|
|
|
+ expect( utils.extend( target, undefined ) ).to.equal( target );
|
|
|
+ expect( utils.extend( target, [] ) ).to.equal( target );
|
|
|
+ expect( utils.extend( target, Date.now() ) ).to.equal( target );
|
|
|
+ expect( utils.extend( target ) ).to.equal( target );
|
|
|
+
|
|
|
+ // None of the above calls should have touched "target".
|
|
|
+ expect( target ).to.have.property( 'a' ).to.equal( 1 );
|
|
|
+ expect( Object.getOwnPropertyNames( target ).length ).to.equal( 1 );
|
|
|
+
|
|
|
+ done();
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
- it( 'should extend by several params in order', function() {
|
|
|
- var target = {
|
|
|
- a: 0,
|
|
|
- b: 0
|
|
|
- };
|
|
|
+ it( 'should extend by several params in order', function( done ) {
|
|
|
+ CKEDITOR.require( [ 'utils' ], function( utils ) {
|
|
|
+ var target = {
|
|
|
+ a: 0,
|
|
|
+ b: 0
|
|
|
+ };
|
|
|
+
|
|
|
+ var ext1 = {
|
|
|
+ b: 1,
|
|
|
+ c: 1
|
|
|
+ };
|
|
|
|
|
|
- var ext1 = {
|
|
|
- b: 1,
|
|
|
- c: 1
|
|
|
- };
|
|
|
+ var ext2 = {
|
|
|
+ c: 2,
|
|
|
+ d: 2
|
|
|
+ };
|
|
|
|
|
|
- var ext2 = {
|
|
|
- c: 2,
|
|
|
- d: 2
|
|
|
- };
|
|
|
+ utils.extend( target, ext1, ext2 );
|
|
|
|
|
|
- utils.extend( target, ext1, ext2 );
|
|
|
+ expect( target ).to.have.property( 'a' ).to.equal( 0 );
|
|
|
+ expect( target ).to.have.property( 'b' ).to.equal( 1 );
|
|
|
+ expect( target ).to.have.property( 'c' ).to.equal( 2 );
|
|
|
+ expect( target ).to.have.property( 'd' ).to.equal( 2 );
|
|
|
|
|
|
- expect( target ).to.have.property( 'a' ).to.equal( 0 );
|
|
|
- expect( target ).to.have.property( 'b' ).to.equal( 1 );
|
|
|
- expect( target ).to.have.property( 'c' ).to.equal( 2 );
|
|
|
- expect( target ).to.have.property( 'd' ).to.equal( 2 );
|
|
|
+ done();
|
|
|
+ } );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
-describe( 'isFunction()', function( utils ) {
|
|
|
- it( 'should be true for functions only', function() {
|
|
|
- var f1 = function() {
|
|
|
- };
|
|
|
-
|
|
|
- /* jshint -W054 */ // The Function constructor is a form of eval
|
|
|
- var f2 = new Function( '' );
|
|
|
- /* jshint +W054 */
|
|
|
-
|
|
|
- expect( utils.isFunction( f1 ) ).to.be.true();
|
|
|
- expect( utils.isFunction( f2 ) ).to.be.true();
|
|
|
-
|
|
|
- expect( utils.isFunction( 1 ) ).to.be.false();
|
|
|
- expect( utils.isFunction( 'a' ) ).to.be.false();
|
|
|
- expect( utils.isFunction( true ) ).to.be.false();
|
|
|
- expect( utils.isFunction( undefined ) ).to.be.false();
|
|
|
- expect( utils.isFunction( [] ) ).to.be.false();
|
|
|
- expect( utils.isFunction( {} ) ).to.be.false();
|
|
|
- expect( utils.isFunction( Date.now() ) ).to.be.false();
|
|
|
+describe( 'isFunction()', function() {
|
|
|
+ it( 'should be true for functions only', function( done ) {
|
|
|
+ CKEDITOR.require( [ 'utils' ], function( utils ) {
|
|
|
+ var f1 = function() {
|
|
|
+ };
|
|
|
+
|
|
|
+ /* jshint -W054 */ // The Function constructor is a form of eval
|
|
|
+ var f2 = new Function( '' );
|
|
|
+ /* jshint +W054 */
|
|
|
+
|
|
|
+ expect( utils.isFunction( f1 ) ).to.be.true();
|
|
|
+ expect( utils.isFunction( f2 ) ).to.be.true();
|
|
|
+
|
|
|
+ expect( utils.isFunction( 1 ) ).to.be.false();
|
|
|
+ expect( utils.isFunction( 'a' ) ).to.be.false();
|
|
|
+ expect( utils.isFunction( true ) ).to.be.false();
|
|
|
+ expect( utils.isFunction( undefined ) ).to.be.false();
|
|
|
+ expect( utils.isFunction( [] ) ).to.be.false();
|
|
|
+ expect( utils.isFunction( {} ) ).to.be.false();
|
|
|
+ expect( utils.isFunction( Date.now() ) ).to.be.false();
|
|
|
+
|
|
|
+ done();
|
|
|
+ } );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
-describe( 'isObject()', function( utils ) {
|
|
|
- it( 'should be true for pure objects only', function() {
|
|
|
- var f1 = function() {
|
|
|
- };
|
|
|
-
|
|
|
- /* jshint -W054 */ // The Function constructor is a form of eval
|
|
|
- var f2 = new Function( '' );
|
|
|
- /* jshint +W054 */
|
|
|
-
|
|
|
- expect( utils.isObject( {} ) ).to.be.true();
|
|
|
- expect( utils.isObject( [] ) ).to.be.true();
|
|
|
-
|
|
|
- expect( utils.isObject( 1 ) ).to.be.false();
|
|
|
- expect( utils.isObject( 'a' ) ).to.be.false();
|
|
|
- expect( utils.isObject( true ) ).to.be.false();
|
|
|
- expect( utils.isObject( undefined ) ).to.be.false();
|
|
|
- expect( utils.isObject( Date.now() ) ).to.be.false();
|
|
|
- expect( utils.isObject( f1 ) ).to.be.false();
|
|
|
- expect( utils.isObject( f2 ) ).to.be.false();
|
|
|
- expect( utils.isObject( null ) ).to.be.false();
|
|
|
+describe( 'isObject()', function() {
|
|
|
+ it( 'should be true for pure objects only', function( done ) {
|
|
|
+ CKEDITOR.require( [ 'utils' ], function( utils ) {
|
|
|
+ var f1 = function() {
|
|
|
+ };
|
|
|
+
|
|
|
+ /* jshint -W054 */ // The Function constructor is a form of eval
|
|
|
+ var f2 = new Function( '' );
|
|
|
+ /* jshint +W054 */
|
|
|
+
|
|
|
+ expect( utils.isObject( {} ) ).to.be.true();
|
|
|
+ expect( utils.isObject( [] ) ).to.be.true();
|
|
|
+
|
|
|
+ expect( utils.isObject( 1 ) ).to.be.false();
|
|
|
+ expect( utils.isObject( 'a' ) ).to.be.false();
|
|
|
+ expect( utils.isObject( true ) ).to.be.false();
|
|
|
+ expect( utils.isObject( undefined ) ).to.be.false();
|
|
|
+ expect( utils.isObject( Date.now() ) ).to.be.false();
|
|
|
+ expect( utils.isObject( f1 ) ).to.be.false();
|
|
|
+ expect( utils.isObject( f2 ) ).to.be.false();
|
|
|
+ expect( utils.isObject( null ) ).to.be.false();
|
|
|
+
|
|
|
+ done();
|
|
|
+ } );
|
|
|
} );
|
|
|
} );
|