|
| 1 | +/** |
| 2 | + * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. |
| 3 | + * For licensing, see LICENSE.md. |
| 4 | + */ |
| 5 | + |
| 6 | +/* global document, Text */ |
| 7 | + |
| 8 | +import isText from '../../src/dom/istext'; |
| 9 | + |
| 10 | +describe( 'isText()', () => { |
| 11 | + it( 'detects native DOM Text', () => { |
| 12 | + expect( isText( new Text( 'foo' ) ) ).to.be.true; |
| 13 | + |
| 14 | + expect( isText( 'foo' ) ).to.be.false; |
| 15 | + expect( isText( {} ) ).to.be.false; |
| 16 | + expect( isText( null ) ).to.be.false; |
| 17 | + expect( isText( undefined ) ).to.be.false; |
| 18 | + expect( isText( new Date() ) ).to.be.false; |
| 19 | + expect( isText( 42 ) ).to.be.false; |
| 20 | + expect( isText( document.createElement( 'div' ) ) ).to.be.false; |
| 21 | + expect( isText( document.createDocumentFragment() ) ).to.be.false; |
| 22 | + expect( isText( document.createComment( 'a' ) ) ).to.be.false; |
| 23 | + } ); |
| 24 | + |
| 25 | + it( 'works for texts in an iframe', done => { |
| 26 | + const iframe = document.createElement( 'iframe' ); |
| 27 | + |
| 28 | + iframe.addEventListener( 'load', () => { |
| 29 | + const iframeDocument = iframe.contentWindow.document; |
| 30 | + |
| 31 | + const textNode = iframeDocument.createTextNode( 'foo' ); |
| 32 | + |
| 33 | + expect( isText( textNode ) ).to.equal( true ); |
| 34 | + |
| 35 | + iframe.remove(); |
| 36 | + done(); |
| 37 | + } ); |
| 38 | + |
| 39 | + document.body.appendChild( iframe ); |
| 40 | + } ); |
| 41 | +} ); |
0 commit comments