8
0

utils.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 not have `called` after creation', function() {
  34. var utils = modules.utils;
  35. var spy = utils.spy();
  36. expect( spy.called ).to.not.be.true();
  37. } );
  38. it( 'should register calls', function() {
  39. var utils = modules.utils;
  40. var fn1 = utils.spy();
  41. var fn2 = utils.spy();
  42. fn1();
  43. expect( fn1.called ).to.be.true();
  44. expect( fn2.called ).to.not.be.true();
  45. } );
  46. } );
  47. describe( 'uid', function() {
  48. it( 'should return different ids', function() {
  49. var utils = modules.utils;
  50. var id1 = utils.uid();
  51. var id2 = utils.uid();
  52. var id3 = utils.uid();
  53. expect( id1 ).to.be.a( 'number' );
  54. expect( id2 ).to.be.a( 'number' ).to.not.equal( id1 ).to.not.equal( id3 );
  55. expect( id3 ).to.be.a( 'number' ).to.not.equal( id1 ).to.not.equal( id2 );
  56. } );
  57. } );
  58. describe( 'Lo-Dash extensions', function() {
  59. // Ensures that the required Lo-Dash extensions are available in `utils`.
  60. it( 'should be exposed in utils', function() {
  61. var utils = modules.utils;
  62. var extensions = modules[ 'utils-lodash' ];
  63. extensions.forEach( function( extension ) {
  64. expect( utils ).to.have.property( extension ).to.not.be.undefined();
  65. } );
  66. } );
  67. } );