element.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* jshint expr: true */
  6. /* bender-tags: document */
  7. 'use strict';
  8. var modules = bender.amd.require(
  9. 'document/node',
  10. 'document/element',
  11. 'document/attribute' );
  12. describe( 'constructor', function() {
  13. it( 'should create element without attributes', function() {
  14. var Element = modules[ 'document/element' ];
  15. var Node = modules[ 'document/node' ];
  16. var parent = new Element( null, 'parent' );
  17. var element = new Element( parent, 'elem' );
  18. expect( element ).to.be.an.instanceof( Node );
  19. expect( element ).to.have.property( 'name' ).that.equals( 'elem' );
  20. expect( element ).to.have.property( 'parent' ).that.equals( parent );
  21. expect( element ).to.have.property( 'attrs' ).that.is.an( 'array' ).and.is.empty;
  22. } );
  23. it( 'should create element with attributes', function() {
  24. var Element = modules[ 'document/element' ];
  25. var Node = modules[ 'document/node' ];
  26. var Attribute = modules[ 'document/attribute' ];
  27. var parent = new Element( null, 'parent' );
  28. var attr = new Attribute( 'key', 'value' );
  29. var element = new Element( parent, 'elem', [ attr ] );
  30. expect( element ).to.be.an.instanceof( Node );
  31. expect( element ).to.have.property( 'name' ).that.equals( 'elem' );
  32. expect( element ).to.have.property( 'parent' ).that.equals( parent );
  33. expect( element ).to.have.property( 'attrs' ).that.is.an( 'array' ).with.length( 1 );
  34. expect( element.attrs[ 0 ] ).that.equals( attr );
  35. } );
  36. } );