import { shallow } from "enzyme"; import * as React from "react"; import { highlight } from "../highlight"; const span = (text: string) => {text}; const em = (text: string) => {text}; const high = (text: string, query: string, sensitive?: boolean) => highlight(text, query, span, em, sensitive); describe("hightlight", () => { it("renders no matches", () => { const res = shallow(
{high("foo bar spam", "eggs")}
); expect(res.equals(
foo bar spam
, )).toBeTruthy(); }); it("renders one match", () => { const res = shallow(
{high("foo bar spam", "bar")}
); expect(res.equals(
foo bar spam
, )).toBeTruthy(); }); it("renders two matches", () => { const res = shallow(
{high("foo bar spam", "a")}
); expect(res.equals(
foo b a r sp a m
, )).toBeTruthy(); }); it("works in case sensitive mode", () => { const res = shallow(
{high("Foo bar spam", "Foo", true)}
); expect(res.equals(
Foo bar spam
, )).toBeTruthy(); const res2 = shallow(
{high("foo bar spam", "Foo", true)}
); expect(res2.equals(
foo bar spam
, )).toBeTruthy(); }); });