Skip to content

Instantly share code, notes, and snippets.

@domitriusclark
Created April 29, 2020 06:58
Show Gist options
  • Save domitriusclark/39418afdd99345056dde84071404aba8 to your computer and use it in GitHub Desktop.
Save domitriusclark/39418afdd99345056dde84071404aba8 to your computer and use it in GitHub Desktop.
single test from useSearch
it('updates data to an array on successful request', async () => {
let server = new Server({
routes() {
this.post("/example-endpoint", () => ({
resources: [
{ id: 1, public_id: "image1" },
{ id: 2, public_id: "image2" },
{ id: 3, public_id: "image3" }
]
}));
},
});
const { result, waitForNextUpdate } = renderHook(() => useSearch({ endpoint: '/example-endpoint' }));
act(() => {
result.current[0]({
expression: "resource_type:image"
})
});
await waitForNextUpdate();
expect(result.current[1].resources[0].id).toBe(1);
expect(result.current[1].resources[1].id).toBe(2);
expect(result.current[1].resources[2].id).toBe(3);
server.shutdown();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment