utils.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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' );
  8. describe( 'extendMixin', function() {
  9. it( 'should extend classes', function() {
  10. var utils = modules.utils;
  11. function Car( name ) {
  12. this.name = name;
  13. }
  14. Car.prototype.addGas = function() {};
  15. Car.extend = utils.extendMixin;
  16. var Truck = Car.extend( {
  17. loadContainers: function() {}
  18. } );
  19. var volvoTruck = new Truck( 'Volvo' );
  20. expect( volvoTruck ).to.be.an.instanceof( Truck );
  21. expect( volvoTruck ).to.be.an.instanceof( Car );
  22. expect( volvoTruck ).to.have.property( 'name' ).to.equals( 'Volvo' );
  23. expect( volvoTruck ).to.have.property( 'addGas' ).to.be.a( 'function' );
  24. expect( volvoTruck ).to.have.property( 'loadContainers' ).to.be.a( 'function' );
  25. var Spacecraft = Truck.extend( {
  26. jumpToHyperspace: function() {}
  27. } );
  28. var falcon = new Spacecraft( 'Millennium Falcon' );
  29. expect( falcon ).to.be.an.instanceof( Spacecraft );
  30. expect( falcon ).to.be.an.instanceof( Truck );
  31. expect( falcon ).to.be.an.instanceof( Car );
  32. expect( falcon ).to.have.property( 'name' ).to.equals( 'Millennium Falcon' );
  33. expect( falcon ).to.have.property( 'addGas' ).to.be.a( 'function' );
  34. expect( falcon ).to.have.property( 'loadContainers' ).to.be.a( 'function' );
  35. expect( falcon ).to.have.property( 'jumpToHyperspace' ).to.be.a( 'function' );
  36. } );
  37. } );
  38. describe( 'spy', function() {
  39. it( 'should register calls', function() {
  40. var utils = modules.utils;
  41. var fn1 = utils.spy();
  42. var fn2 = utils.spy();
  43. fn1();
  44. expect( fn1.called ).to.be.true();
  45. expect( fn2.called ).to.not.be.true();
  46. } );
  47. } );
  48. describe( 'uid', function() {
  49. it( 'should return different ids', function() {
  50. var utils = modules.utils;
  51. var id1 = utils.uid();
  52. var id2 = utils.uid();
  53. var id3 = utils.uid();
  54. expect( id1 ).to.be.a( 'number' );
  55. expect( id2 ).to.be.a( 'number' ).to.not.equal( id1 ).to.not.equal( id3 );
  56. expect( id3 ).to.be.a( 'number' ).to.not.equal( id1 ).to.not.equal( id2 );
  57. } );
  58. } );