Created
May 16, 2017 19:18
-
-
Save mikebridge/32c3b47f07d29f33b6dbda32e2796157 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("{"foo":"bar"}"); | |
}); | |
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