istext.js 1.2 KB

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