createelement.js 1.4 KB

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