import {shallow} from "enzyme"; import * as React from "react"; import {actions} from "redux-router5"; import createRouter from "router5"; import {UnconnectedLink} from "./Link"; /* tslint:disable:no-empty jsx-no-lambda */ describe("", () => { const routes = [ {name: "home", path: "/"}, {name: "about", path: "/about"}, {name: "counter", path: "/counter"}, {name: "register", path: "/register"}, {name: "stars", path: "/stars"}, {name: "products", path: "/products"}, {name: "product", path: "/product/:id"}, {name: "account", path: "/account"}, {name: "account.orders", path: "/orders"}, {name: "account.order", path: "/order/:id"} ]; const router = createRouter(routes); it("renders href correctly", () => { let component; component = shallow(, {context: {router}}); expect(component.find("a")).toHaveProp("href", "/"); component = shallow( , {context: {router}} ); expect(component.find("a")).toHaveProp("href", "/product/10"); component = shallow( , {context: {router}} ); expect(component.find("a")).toHaveProp("href", "/account/order/10"); }); it("renders active class", () => { router.setState({ name: "account.order", params: {id: 10}, path: "/" }); const component = shallow( , {context: {router}} ); expect(component.find("a")).toHaveClassName("active"); }); it("does not render active class", () => { router.setState({ name: "home", params: {}, path: "/" }); const component = shallow(, {context: {router}}); expect(component.find("a")).not.toHaveClassName("active"); }); it("calls dispatch with correct arguments when clicked", () => { const dispatch = jest.fn(); const component = shallow(, {context: {router}}); expect(dispatch).not.toHaveBeenCalled(); component.find("a").simulate("click", { preventDefault(): void {} }); expect(dispatch).toHaveBeenCalledWith(actions.navigateTo("home")); }); });