Skip to content

Commit 19d1d93

Browse files
committed
Add additional test for preventCallFetch/depends
1 parent 36f627b commit 19d1d93

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/__tests__/useFetch.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,29 @@ describe("useFetch", () => {
126126
});
127127
});
128128

129+
it("call with url, options with preventCallFetch: false and depends", async () => {
130+
fetch.mockResponse(JSON.stringify({ data: "12345" }));
131+
const options = {
132+
headers: {
133+
Accept: "application/json, application/xml, text/plain, text/html, *.*",
134+
"Content-Type": "application/json; charset=utf-8"
135+
}
136+
};
137+
138+
const Component = () => {
139+
const result = useFetch("https://google.com", { ...options, depends: ["xxx"], preventCallFetch: false });
140+
return <div>{result.data && result.data.data}</div>;
141+
};
142+
143+
const { container, rerender } = render(<Component />);
144+
145+
await wait(() => {
146+
rerender(<Component />);
147+
148+
expect(fetch.mock.calls.length).toEqual(1);
149+
});
150+
});
151+
129152
it("call with url, options with depends", async () => {
130153
fetch.mockResponse(JSON.stringify({ data: "12345" }));
131154
const options = {

0 commit comments

Comments
 (0)