Skip to content

Instantly share code, notes, and snippets.

@Swiip
Created March 19, 2019 16:55
Show Gist options
  • Save Swiip/e98daa47e61cb60a5552af04191a07bd to your computer and use it in GitHub Desktop.
Save Swiip/e98daa47e61cb60a5552af04191a07bd to your computer and use it in GitHub Desktop.
components/company/__tests__/AgenciesMenu.js
import React from "react";
import { shallow } from "enzyme";
import Router from "next/router";
import AgenciesMenu from "../AgenciesMenu";
import { setAgencies, selectAgency } from "../../../logic/hooks/useAgencies";
const lyon = { slug: "lyon" };
const paris = { slug: "paris" };
const agencies = [lyon, paris];
jest.mock("../../../logic/hooks/useAgencies");
test("should match snapshot", () => {
setAgencies(agencies);
const cmp = shallow(<AgenciesMenu />);
expect(cmp).toMatchSnapshot();
});
test("should provide a select agency handler which call the action and route", () => {
setAgencies(agencies);
const cmp = shallow(<AgenciesMenu />);
const handleAgency = cmp
.find("AgenciesMenu__Item")
.first()
.prop("onClick");
handleAgency();
expect(selectAgency).toHaveBeenCalled();
expect(Router.push).toHaveBeenCalled();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment