8
0

createelement.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  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 namespace', () => {
  20. const namespace = 'http://www.w3.org/2000/svg';
  21. const svg = createElement( document, 'svg', { xmlns: namespace } );
  22. expect( svg.tagName.toLowerCase() ).to.equal( 'svg' );
  23. expect( svg.getAttribute( 'xmlns' ) ).to.equal( namespace );
  24. expect( svg.createSVGRect ).to.be.a( 'function' );
  25. } );
  26. it( 'should create element with child text node', () => {
  27. const p = createElement( document, 'p', null, 'foo' );
  28. expect( p.tagName.toLowerCase() ).to.equal( 'p' );
  29. expect( p.childNodes.length ).to.equal( 1 );
  30. expect( p.childNodes[ 0 ].data ).to.equal( 'foo' );
  31. } );
  32. it( 'should create ', () => {
  33. const p = createElement( document, 'p', null, [ 'foo', createElement( document, 'img' ) ] );
  34. expect( p.tagName.toLowerCase() ).to.equal( 'p' );
  35. expect( p.childNodes.length ).to.equal( 2 );
  36. expect( p.childNodes[ 0 ].data ).to.equal( 'foo' );
  37. expect( p.childNodes[ 1 ].tagName.toLowerCase() ).to.equal( 'img' );
  38. } );
  39. } );