createelement.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import createElement from '../../src/dom/createelement';
  7. describe( 'createElement', () => {
  8. it( 'should create element', () => {
  9. const p = createElement( document, 'p' );
  10. expect( p.tagName.toLowerCase() ).to.equal( 'p' );
  11. expect( p.childNodes.length ).to.equal( 0 );
  12. } );
  13. it( 'should create element with attribute', () => {
  14. const p = createElement( document, 'p', { class: 'foo' } );
  15. expect( p.tagName.toLowerCase() ).to.equal( 'p' );
  16. expect( p.childNodes.length ).to.equal( 0 );
  17. expect( p.getAttribute( 'class' ) ).to.equal( 'foo' );
  18. } );
  19. it( 'should create element with child text node', () => {
  20. const p = createElement( document, 'p', null, 'foo' );
  21. expect( p.tagName.toLowerCase() ).to.equal( 'p' );
  22. expect( p.childNodes.length ).to.equal( 1 );
  23. expect( p.childNodes[ 0 ].data ).to.equal( 'foo' );
  24. } );
  25. it( 'should create ', () => {
  26. const p = createElement( document, 'p', null, [ 'foo', createElement( document, 'img' ) ] );
  27. expect( p.tagName.toLowerCase() ).to.equal( 'p' );
  28. expect( p.childNodes.length ).to.equal( 2 );
  29. expect( p.childNodes[ 0 ].data ).to.equal( 'foo' );
  30. expect( p.childNodes[ 1 ].tagName.toLowerCase() ).to.equal( 'img' );
  31. } );
  32. } );