8
0

basicclass.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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( 'basicclass' );
  8. describe( 'extend', function() {
  9. it( 'should extend classes', function() {
  10. var BasicClass = modules.basicclass;
  11. var Truck = BasicClass.extend( {
  12. loadContainers: function() {}
  13. } );
  14. var volvoTruck = new Truck();
  15. expect( volvoTruck ).to.be.an.instanceof( Truck );
  16. expect( volvoTruck ).to.be.an.instanceof( BasicClass );
  17. expect( volvoTruck ).to.have.property( 'loadContainers' ).to.be.a( 'function' );
  18. var Spacecraft = Truck.extend( {
  19. jumpToHyperspace: function() {}
  20. } );
  21. var falcon = new Spacecraft();
  22. expect( falcon ).to.be.an.instanceof( Spacecraft );
  23. expect( falcon ).to.be.an.instanceof( Truck );
  24. expect( falcon ).to.be.an.instanceof( BasicClass );
  25. expect( falcon ).to.have.property( 'loadContainers' ).to.be.a( 'function' );
  26. expect( falcon ).to.have.property( 'jumpToHyperspace' ).to.be.a( 'function' );
  27. } );
  28. it( 'should extend the prototype and add statics', function() {
  29. var BasicClass = modules.basicclass;
  30. var Truck = BasicClass.extend( {
  31. property1: 1,
  32. property2: function() {}
  33. }, {
  34. static1: 1,
  35. static2: function() {}
  36. } );
  37. expect( Truck ).to.have.property( 'static1' ).to.equal( 1 );
  38. expect( Truck ).to.have.property( 'static2' ).to.be.a( 'function' );
  39. var truck = new Truck();
  40. expect( truck ).to.have.property( 'property1' ).to.equal( 1 );
  41. expect( truck ).to.have.property( 'property2' ).to.be.a( 'function' );
  42. } );
  43. it( 'should use a custom constructor', function() {
  44. var BasicClass = modules.basicclass;
  45. function customConstructor() {}
  46. var Truck = BasicClass.extend( {
  47. constructor: customConstructor
  48. } );
  49. expect( Truck ).to.equal( customConstructor );
  50. expect( Truck.prototype ).to.not.have.ownProperty( 'constructor' );
  51. expect( new Truck() ).to.be.an.instanceof( Truck );
  52. expect( new Truck() ).to.be.an.instanceof( BasicClass );
  53. } );
  54. } );
  55. describe( 'BasicClass', function() {
  56. it( 'should be an event emitter', function() {
  57. var BasicClass = modules.basicclass;
  58. var basic = new BasicClass();
  59. expect( basic ).to.have.property( 'fire' ).to.be.a( 'function' );
  60. } );
  61. } );