8
0

indexof.js 872 B

1234567891011121314151617181920212223242526272829303132
  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 indexOf from 'ckeditor5/utils/dom/indexof.js';
  8. describe( 'indexOf', () => {
  9. it( 'should return 0 if element has no parent', () => {
  10. const p = document.createElement( 'p' );
  11. expect( indexOf( p ) ).to.equal( 0 );
  12. } );
  13. it( 'should return index of the node in parent', () => {
  14. const div = document.createElement( 'div' );
  15. const p0 = document.createElement( 'p' );
  16. const p1 = document.createElement( 'p' );
  17. const p2 = document.createElement( 'p' );
  18. div.appendChild( p0 );
  19. div.appendChild( p1 );
  20. div.appendChild( p2 );
  21. expect( indexOf( p0 ) ).to.equal( 0 );
  22. expect( indexOf( p1 ) ).to.equal( 1 );
  23. expect( indexOf( p2 ) ).to.equal( 2 );
  24. } );
  25. } );