Skip to content

Instantly share code, notes, and snippets.

@mikebridge
Created May 16, 2017 19:18
Show Gist options
  • Save mikebridge/32c3b47f07d29f33b6dbda32e2796157 to your computer and use it in GitHub Desktop.
Save mikebridge/32c3b47f07d29f33b6dbda32e2796157 to your computer and use it in GitHub Desktop.
import * as React from "react";
import {shallow, mount} from "enzyme";
import withQueryString from "./withQueryString";
import {IQueryStringProps} from "./withQueryString";
import {MemoryRouter} from "react-router";
interface ITestComponentOwnProps {}
class TestComponent extends React.Component<IQueryStringProps & ITestComponentOwnProps, {}> {
public render(): JSX.Element {
const qsProps = JSON.stringify(this.props.params);
return (<div>{qsProps}</div>);
}
}
describe("withQueryString", () => {
const TestComponentWithQueryString = withQueryString(TestComponent);
it("injects the query string into the component as an object", () => {
const wrapper = shallow(
<MemoryRouter initialEntries={["/test?foo=bar"]}>
<TestComponentWithQueryString />
</MemoryRouter>);
expect(wrapper.html()).toContain("{&quot;foo&quot;:&quot;bar&quot;}");
});
it("injects an empty object when no query string", () => {
const wrapper = shallow(
<MemoryRouter initialEntries={["/test"]}>
<TestComponentWithQueryString />
</MemoryRouter>);
expect(wrapper.html()).toContain("{}");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment