|
|
@@ -5,30 +5,30 @@
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
-var modules = bender.amd.require( 'utils', 'utils-lodash' );
|
|
|
+const modules = bender.amd.require( 'utils', 'utils-lodash' );
|
|
|
|
|
|
-describe( 'utils', function() {
|
|
|
- var utils;
|
|
|
+describe( 'utils', () => {
|
|
|
+ let utils;
|
|
|
|
|
|
- before( function() {
|
|
|
+ before( () => {
|
|
|
utils = modules.utils;
|
|
|
} );
|
|
|
|
|
|
- describe( 'extend()', function() {
|
|
|
+ describe( 'extend()', () => {
|
|
|
// 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() {
|
|
|
- var target = {
|
|
|
+ it( 'should extend by several params in the correct order', () => {
|
|
|
+ let target = {
|
|
|
a: 0,
|
|
|
b: 0
|
|
|
};
|
|
|
|
|
|
- var ext1 = {
|
|
|
+ let ext1 = {
|
|
|
b: 1,
|
|
|
c: 1
|
|
|
};
|
|
|
|
|
|
- var ext2 = {
|
|
|
+ let ext2 = {
|
|
|
c: 2,
|
|
|
d: 2
|
|
|
};
|
|
|
@@ -42,16 +42,16 @@ describe( 'utils', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- describe( 'spy', function() {
|
|
|
- it( 'should not have `called` after creation', function() {
|
|
|
- var spy = utils.spy();
|
|
|
+ describe( 'spy', () => {
|
|
|
+ it( 'should not have `called` after creation', () => {
|
|
|
+ let spy = utils.spy();
|
|
|
|
|
|
expect( spy.called ).to.not.be.true();
|
|
|
} );
|
|
|
|
|
|
- it( 'should register calls', function() {
|
|
|
- var fn1 = utils.spy();
|
|
|
- var fn2 = utils.spy();
|
|
|
+ it( 'should register calls', () => {
|
|
|
+ let fn1 = utils.spy();
|
|
|
+ let fn2 = utils.spy();
|
|
|
|
|
|
fn1();
|
|
|
|
|
|
@@ -60,11 +60,11 @@ describe( 'utils', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- describe( 'uid', function() {
|
|
|
- it( 'should return different ids', function() {
|
|
|
- var id1 = utils.uid();
|
|
|
- var id2 = utils.uid();
|
|
|
- var id3 = utils.uid();
|
|
|
+ describe( 'uid', () => {
|
|
|
+ it( 'should return different ids', () => {
|
|
|
+ let id1 = utils.uid();
|
|
|
+ let id2 = utils.uid();
|
|
|
+ let id3 = utils.uid();
|
|
|
|
|
|
expect( id1 ).to.be.a( 'number' );
|
|
|
expect( id2 ).to.be.a( 'number' ).to.not.equal( id1 ).to.not.equal( id3 );
|
|
|
@@ -72,20 +72,20 @@ describe( 'utils', function() {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- describe( 'isIterable', function() {
|
|
|
- it( 'should be true for string', function() {
|
|
|
- var string = 'foo';
|
|
|
+ describe( 'isIterable', () => {
|
|
|
+ it( 'should be true for string', () => {
|
|
|
+ let string = 'foo';
|
|
|
|
|
|
expect( utils.isIterable( string ) ).to.be.true;
|
|
|
} );
|
|
|
|
|
|
- it( 'should be true for arrays', function() {
|
|
|
- var array = [ 1, 2, 3 ];
|
|
|
+ it( 'should be true for arrays', () => {
|
|
|
+ let array = [ 1, 2, 3 ];
|
|
|
|
|
|
expect( utils.isIterable( array ) ).to.be.true;
|
|
|
} );
|
|
|
|
|
|
- it( 'should be true for iterable classes', function() {
|
|
|
+ it( 'should be true for iterable classes', () => {
|
|
|
class IterableClass {
|
|
|
constructor() {
|
|
|
this.array = [ 1, 2, 3 ];
|
|
|
@@ -96,67 +96,95 @@ describe( 'utils', function() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- var instance = new IterableClass();
|
|
|
+ let instance = new IterableClass();
|
|
|
|
|
|
expect( utils.isIterable( instance ) ).to.be.true;
|
|
|
} );
|
|
|
|
|
|
- it( 'should be false for not iterable objects', function() {
|
|
|
- var notIterable = { foo: 'bar' };
|
|
|
+ it( 'should be false for not iterable objects', () => {
|
|
|
+ let notIterable = { foo: 'bar' };
|
|
|
|
|
|
expect( utils.isIterable( notIterable ) ).to.be.false;
|
|
|
} );
|
|
|
|
|
|
- it( 'should be false for undefined', function() {
|
|
|
+ it( 'should be false for undefined', () => {
|
|
|
expect( utils.isIterable() ).to.be.false;
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- describe( 'compareArrays', function() {
|
|
|
- it( 'should return SAME flag, when arrays are same', function() {
|
|
|
- var a = [ 'abc', 0, 3 ];
|
|
|
- var b = [ 'abc', 0, 3 ];
|
|
|
+ describe( 'compareArrays', () => {
|
|
|
+ it( 'should return SAME flag, when arrays are same', () => {
|
|
|
+ let a = [ 'abc', 0, 3 ];
|
|
|
+ let b = [ 'abc', 0, 3 ];
|
|
|
|
|
|
- var result = utils.compareArrays( a, b );
|
|
|
+ let result = utils.compareArrays( a, b );
|
|
|
|
|
|
expect( result ).to.equal( utils.compareArrays.SAME );
|
|
|
} );
|
|
|
|
|
|
- it( 'should return PREFIX flag, when all n elements of first array are same as n first elements of the second array', function() {
|
|
|
- var a = [ 'abc', 0 ];
|
|
|
- var b = [ 'abc', 0, 3 ];
|
|
|
+ it( 'should return PREFIX flag, when all n elements of first array are same as n first elements of the second array', () => {
|
|
|
+ let a = [ 'abc', 0 ];
|
|
|
+ let b = [ 'abc', 0, 3 ];
|
|
|
|
|
|
- var result = utils.compareArrays( a, b );
|
|
|
+ let result = utils.compareArrays( a, b );
|
|
|
|
|
|
expect( result ).to.equal( utils.compareArrays.PREFIX );
|
|
|
} );
|
|
|
|
|
|
- it( 'should return EXTENSION flag, when n first elements of first array are same as all elements of the second array', function() {
|
|
|
- var a = [ 'abc', 0, 3 ];
|
|
|
- var b = [ 'abc', 0 ];
|
|
|
+ it( 'should return EXTENSION flag, when n first elements of first array are same as all elements of the second array', () => {
|
|
|
+ let a = [ 'abc', 0, 3 ];
|
|
|
+ let b = [ 'abc', 0 ];
|
|
|
|
|
|
- var result = utils.compareArrays( a, b );
|
|
|
+ let result = utils.compareArrays( a, b );
|
|
|
|
|
|
expect( result ).to.equal( utils.compareArrays.EXTENSION );
|
|
|
} );
|
|
|
|
|
|
- it( 'should return DIFFERENT flag, when arrays are not same', function() {
|
|
|
- var a = [ 'abc', 0, 3 ];
|
|
|
- var b = [ 'abc', 1, 3 ];
|
|
|
+ it( 'should return DIFFERENT flag, when arrays are not same', () => {
|
|
|
+ let a = [ 'abc', 0, 3 ];
|
|
|
+ let b = [ 'abc', 1, 3 ];
|
|
|
|
|
|
- var result = utils.compareArrays( a, b );
|
|
|
+ let result = utils.compareArrays( a, b );
|
|
|
|
|
|
expect( result ).to.equal( utils.compareArrays.DIFFERENT );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- describe( 'Lo-Dash extensions', function() {
|
|
|
+ describe( 'nth', () => {
|
|
|
+ it( 'should return 0th item', () => {
|
|
|
+ expect( utils.nth( 0, getIterator() ) ).to.equal( 11 );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return the last item', () => {
|
|
|
+ expect( utils.nth( 2, getIterator() ) ).to.equal( 33 );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return null if out of range (bottom)', () => {
|
|
|
+ expect( utils.nth( -1, getIterator() ) ).to.be.null;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return null if out of range (top)', () => {
|
|
|
+ expect( utils.nth( 3, getIterator() ) ).to.be.null;
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return null if iterator is empty', () => {
|
|
|
+ expect( utils.nth( 0, [] ) ).to.be.null;
|
|
|
+ } );
|
|
|
+
|
|
|
+ function *getIterator() {
|
|
|
+ yield 11;
|
|
|
+ yield 22;
|
|
|
+ yield 33;
|
|
|
+ }
|
|
|
+ } );
|
|
|
+
|
|
|
+ describe( 'Lo-Dash extensions', () => {
|
|
|
// Ensures that the required Lo-Dash extensions are available in `utils`.
|
|
|
- it( 'should be exposed in utils', function() {
|
|
|
- var utils = modules.utils;
|
|
|
- var extensions = modules[ 'utils-lodash' ];
|
|
|
+ it( 'should be exposed in utils', () => {
|
|
|
+ let utils = modules.utils;
|
|
|
+ let extensions = modules[ 'utils-lodash' ];
|
|
|
|
|
|
- extensions.forEach( function( extension ) {
|
|
|
+ extensions.forEach( ( extension ) => {
|
|
|
expect( utils ).to.have.property( extension ).to.not.be.undefined();
|
|
|
} );
|
|
|
} );
|