Last active
July 11, 2019 13:01
-
-
Save ramsaylanier/37454b1847b3e67ff192ed48d00548b5 to your computer and use it in GitHub Desktop.
Testing Dispatch Actions With Jest
This file contains 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 { useDispatch, StoreProvider } from "@/state/store" | |
import mockClient from "@/tests/mocks/mockClient" | |
import { UserQuery } from "@graphql/user/queries.graphql" | |
let r, data, dispatch | |
const DispatchWrapper = props => { | |
dispatch = useDispatch() | |
return props.children | |
} | |
const Component = props => { | |
return ( | |
<StoreProvider> | |
<DispatchWrapper> | |
<SearchResultsView {...props}/> | |
</DispatchWrapper> | |
</StoreProvider> | |
) | |
} | |
beforeAll(async () => { | |
let {data} = await mockClient.query({ query: UserQuery }) | |
r = render(Component(data)) | |
}) | |
afterAll(() => { | |
cleanup() | |
}) | |
describe("<SearchResultsView />", () => { | |
it("should display results", async () => { | |
dispatch({ | |
type: "updateSearchString", | |
payload: { queryString: "puppies" } | |
}) | |
r.rerender(Component(data)) | |
const list = await waitForElement(() => | |
r.container.querySelector("#entity-list") | |
) | |
const results = list.querySelectorAll("li") | |
expect(results.length).toBe(10) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment