import highlight from '~/lib/utils/highlight'; describe('highlight', () => { it(`should appropriately surround substring matches`, () => { const expected = 'gitlab'; expect(highlight('gitlab', 'it')).toBe(expected); }); it(`should return an empty string in the case of invalid inputs`, () => { [null, undefined].forEach(input => { expect(highlight(input, 'match')).toBe(''); }); }); it(`should return the original value if match is null, undefined, or ''`, () => { [null, undefined].forEach(match => { expect(highlight('gitlab', match)).toBe('gitlab'); }); }); it(`should highlight matches in non-string inputs`, () => { const expected = '123456'; expect(highlight(123456, 45)).toBe(expected); }); it(`should sanitize the input string before highlighting matches`, () => { const expected = 'hello world'; expect(highlight('hello world', 'w')).toBe(expected); }); it(`should not highlight anything if no matches are found`, () => { expect(highlight('gitlab', 'hello')).toBe('gitlab'); }); it(`should allow wrapping elements to be customized`, () => { const expected = '123'; expect(highlight('123', '2', '', '')).toBe(expected); }); });