get-parent.js 909 B

123456789101112131415161718192021222324252627282930
  1. QUnit.test( 'getParent', function( assert ) {
  2. var getParent = fizzyUIUtils.getParent;
  3. var gridA = document.querySelector('.grid-a');
  4. var itemA1 = document.querySelector('.item-a1');
  5. var parent = getParent( itemA1, '.grid' );
  6. assert.equal( parent, gridA, 'got grid parent from item' );
  7. parent = getParent( document.querySelector('.span-a3'), '.grid' );
  8. assert.equal( parent, gridA, 'got grid parent from span' );
  9. parent = getParent( itemA1, '#qunit' );
  10. assert.ok( parent === undefined, 'parent not tree is undefined' );
  11. var treeNotInDocument = document.createElement('div');
  12. treeNotInDocument.innerHTML =
  13. '<div class="a">' +
  14. '<div class="a1">' +
  15. '</div>';
  16. parent = getParent( treeNotInDocument.querySelector('.a1'), '.not-found' );
  17. assert.ok(
  18. parent === undefined,
  19. 'Parent should be `undefined` even when the given tree is not in the document'
  20. );
  21. });