indexof.js 876 B

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