import * as React from "react";
import { create } from "react-test-renderer";
import Switch from "../switch";
// Test components
const TestArchive: React.FC<{ when?: boolean; someProp?: string }> = () => {
return
Test Archive Component
;
};
const TestBlog: React.FC<{ when?: boolean }> = () => {
return Test Blog Component
;
};
// Default test component
const Default: React.FC<{ someProp?: string }> = () => {
return Default Component
;
};
describe("Switch", () => {
test("should render the default component if no match was found", () => {
const SwitchComponent = create(
);
expect(SwitchComponent.toJSON()).toMatchSnapshot();
});
test("should render the first component that match", () => {
const SwitchComponent = create(
);
expect(SwitchComponent.toJSON()).toMatchSnapshot();
});
test("should return null if no component match", () => {
const SwitchComponent = create(
);
expect(SwitchComponent.toJSON()).toMatchSnapshot();
});
test("should pass down any prop that the matching component receives", () => {
const SwitchComponent = create(
);
expect(SwitchComponent.root.findByType(TestArchive).props).toEqual({
someProp: "prop value",
});
});
test("should pass down any prop of the default component", () => {
const SwitchComponent = create(
);
expect(SwitchComponent.root.findByType(Default).props).toEqual({
someProp: "prop value",
});
});
});