|
@@ -10,66 +10,8 @@
|
|
|
var modules = bender.amd.require( 'utils' );
|
|
var modules = bender.amd.require( 'utils' );
|
|
|
|
|
|
|
|
describe( 'extend()', function() {
|
|
describe( 'extend()', function() {
|
|
|
- it( 'should extend and override', function() {
|
|
|
|
|
- var utils = modules.utils;
|
|
|
|
|
-
|
|
|
|
|
- var target = {
|
|
|
|
|
- a: 1,
|
|
|
|
|
- b: 2
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- var extensions = {
|
|
|
|
|
- a: 'A',
|
|
|
|
|
- c: 3,
|
|
|
|
|
-
|
|
|
|
|
- // Extend by reference (no deep-copy).
|
|
|
|
|
- obj: {
|
|
|
|
|
- a: 1
|
|
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
- // Extend by reference (no deep-copy).
|
|
|
|
|
- arr: [ 1, 2 ],
|
|
|
|
|
-
|
|
|
|
|
- // Extend by reference.
|
|
|
|
|
- fn: function() {}
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- 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 ).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 );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should not be touched by non-objects', function() {
|
|
|
|
|
- var utils = modules.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, new Date() ) ).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 );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- // Properties of the subsequent objects should override properties of the preceding objects.
|
|
|
|
|
|
|
+ // Properties of the subsequent objects should override properties of the preceding objects. This is critical for
|
|
|
|
|
+ // CKEditor so we keep this test to ensure that Lo-Dash (or whatever) implements it in the way we need it.
|
|
|
it( 'should extend by several params in the correct order', function() {
|
|
it( 'should extend by several params in the correct order', function() {
|
|
|
var utils = modules.utils;
|
|
var utils = modules.utils;
|
|
|
|
|
|