isdomnode.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. /* global document, window */
  6. import isNode from '../../src/dom/isnode';
  7. describe( 'isNode()', () => {
  8. it( 'detects native DOM nodes', () => {
  9. expect( isNode( document ) ).to.be.true;
  10. expect( isNode( document.createElement( 'div' ) ) ).to.be.true;
  11. expect( isNode( document.createTextNode( 'Foo' ) ) ).to.be.true;
  12. expect( isNode( {} ) ).to.be.false;
  13. expect( isNode( null ) ).to.be.false;
  14. expect( isNode( undefined ) ).to.be.false;
  15. expect( isNode( new Date() ) ).to.be.false;
  16. expect( isNode( 42 ) ).to.be.false;
  17. expect( isNode( window ) ).to.be.false;
  18. } );
  19. it( 'works for nodes in an iframe', done => {
  20. const iframe = document.createElement( 'iframe' );
  21. iframe.addEventListener( 'load', () => {
  22. const iframeDocument = iframe.contentWindow.document;
  23. expect( isNode( iframeDocument ) ).to.be.true;
  24. expect( isNode( iframeDocument.createElement( 'div' ) ) ).to.be.true;
  25. expect( isNode( iframeDocument.createTextNode( 'Foo' ) ) ).to.be.true;
  26. expect( isNode( iframe.contentWindow ) ).to.be.false;
  27. iframe.remove();
  28. done();
  29. } );
  30. document.body.appendChild( iframe );
  31. } );
  32. } );