/** * @jest-environment jsdom */ import { capitalPDangit, parseHtml, preventWidows } from '../index'; describe( 'formatting', () => { describe( '#capitalPDangtest()', function () { test( 'should error when input is not a string', function () { const types = [ {}, undefined, 1, true, [], function () {} ]; types.forEach( function ( type ) { expect( function () { capitalPDangit( type ); } ).toThrow( Error ); } ); } ); test( 'should not modify wordpress', function () { const strings = [ 'wordpress', 'I love wordpress' ]; strings.forEach( function ( string ) { expect( capitalPDangit( string ) ).toBe( string ); } ); } ); test( 'should return WordPress with a capital P when passed Wordpress', function () { expect( capitalPDangit( 'Wordpress' ) ).toBe( 'WordPress' ); expect( capitalPDangit( 'I love Wordpress' ) ).toBe( 'I love WordPress' ); } ); test( 'should replace all instances of Wordpress', function () { expect( capitalPDangit( 'Wordpress Wordpress' ) ).toBe( 'WordPress WordPress' ); expect( capitalPDangit( 'I love Wordpress and Wordpress loves me' ) ).toBe( 'I love WordPress and WordPress loves me' ); } ); } ); describe( '#parseHtml()', function () { test( 'should equal to null when input is not a string', function () { const types = [ {}, undefined, 1, true, [], function () {} ]; types.forEach( function ( type ) { expect( parseHtml( type ) ).toBeNull(); } ); } ); test( 'should return a DOM element if you pass in DOM element', function () { const div = document.createElement( 'div' ); expect( div ).toBe( parseHtml( div ) ); } ); test( 'should return a document fragment if we pass in a string', function () { const fragment = parseHtml( 'hello' ); expect( typeof fragment.querySelector ).toBe( 'function' ); expect( fragment.querySelectorAll( '*' ) ).toHaveLength( 0 ); } ); test( 'should return a document fragment if we pass in a HTML string', function () { const fragment = parseHtml( '