describe('highlightText', function() { const cyrillicTerm = 'шеллы'; const umlautTerm = 'gänsefüßchen'; it('should highlight text incl. special characters correctly in HTML', function() { const highlightTestSpan = new DOMParser().parseFromString( 'This is the шеллы and Gänsefüßchen test!', 'text/html').body.firstChild _highlightText(highlightTestSpan, cyrillicTerm, 'highlighted'); _highlightText(highlightTestSpan, umlautTerm, 'highlighted'); const expectedHtmlString = 'This is the шеллы and ' + 'Gänsefüßchen test!'; expect(highlightTestSpan.innerHTML).toEqual(expectedHtmlString); }); it('should highlight text incl. special characters correctly in SVG', function() { const highlightTestSvg = new DOMParser().parseFromString( '' + '' + '' + 'This is the шеллы and Gänsefüßchen test!' + '' + '' + '', 'text/html').body.firstChild _highlightText(highlightTestSvg, cyrillicTerm, 'highlighted'); _highlightText(highlightTestSvg, umlautTerm, 'highlighted'); /* Note wild cards and ``toMatch``; allowing for some variability seems to be necessary, even between different FF versions */ const expectedSvgString = '' + '' + '' + 'This is the шеллы and ' + 'Gänsefüßchen test!'; expect(new XMLSerializer().serializeToString(highlightTestSvg.firstChild)).toMatch(new RegExp(expectedSvgString)); }); });