8
0

utils.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals describe, it, expect, bender */
  6. 'use strict';
  7. var modules = bender.amd.require( 'utils', 'utils-lodash' );
  8. describe( 'extend()', function() {
  9. // Properties of the subsequent objects should override properties of the preceding objects. This is critical for
  10. // CKEditor so we keep this test to ensure that Lo-Dash (or whatever) implements it in the way we need it.
  11. it( 'should extend by several params in the correct order', function() {
  12. var utils = modules.utils;
  13. var target = {
  14. a: 0,
  15. b: 0
  16. };
  17. var ext1 = {
  18. b: 1,
  19. c: 1
  20. };
  21. var ext2 = {
  22. c: 2,
  23. d: 2
  24. };
  25. utils.extend( target, ext1, ext2 );
  26. expect( target ).to.have.property( 'a' ).to.equal( 0 );
  27. expect( target ).to.have.property( 'b' ).to.equal( 1 );
  28. expect( target ).to.have.property( 'c' ).to.equal( 2 );
  29. expect( target ).to.have.property( 'd' ).to.equal( 2 );
  30. } );
  31. } );
  32. describe( 'spy', function() {
  33. it( 'should register calls', function() {
  34. var utils = modules.utils;
  35. var fn1 = utils.spy();
  36. var fn2 = utils.spy();
  37. fn1();
  38. expect( fn1.called ).to.be.true();
  39. expect( fn2.called ).to.not.be.true();
  40. } );
  41. } );
  42. describe( 'uid', function() {
  43. it( 'should return different ids', function() {
  44. var utils = modules.utils;
  45. var id1 = utils.uid();
  46. var id2 = utils.uid();
  47. var id3 = utils.uid();
  48. expect( id1 ).to.be.a( 'number' );
  49. expect( id2 ).to.be.a( 'number' ).to.not.equal( id1 ).to.not.equal( id3 );
  50. expect( id3 ).to.be.a( 'number' ).to.not.equal( id1 ).to.not.equal( id2 );
  51. } );
  52. } );
  53. describe( 'Lo-Dash extensions', function() {
  54. // Ensures that the required Lo-Dash extensions are available in `utils`.
  55. it( 'should be exposed in utils', function() {
  56. var utils = modules.utils;
  57. var extensions = modules[ 'utils-lodash' ];
  58. extensions.forEach( function( extension ) {
  59. expect( utils ).to.have.property( extension ).to.not.be.undefined();
  60. } );
  61. } );
  62. } );