react-fetch-hook
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -16,2 +16,6 @@ "use strict"; | ||
var defaultFormatter = function defaultFormatter(response) { | ||
if (!response.ok) { | ||
throw Error(response.statusText); | ||
} | ||
return response.json(); | ||
@@ -18,0 +22,0 @@ }; |
{ | ||
"name": "react-fetch-hook", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "React fetch hook", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -82,2 +82,21 @@ import React from "react"; | ||
}); | ||
it("error on throw error", async () => { | ||
fetch.mockReject(new Error("fake error message")); | ||
const Component = () => { | ||
const result = useFetch("https://google.com"); | ||
return (result.error && result.error.message) || "text"; | ||
}; | ||
const { container, rerender } = render(<Component />); | ||
await wait(() => { | ||
rerender(<Component />); | ||
expect(fetch.mock.calls.length).toEqual(1); | ||
expect(container).toHaveTextContent("fake error message"); | ||
expect(fetch.mock.calls[0][0]).toEqual("https://google.com"); | ||
}); | ||
}); | ||
}); |
@@ -14,3 +14,8 @@ // @flow | ||
): TUseFetchResult<T> { | ||
const defaultFormatter = response => response.json(); | ||
const defaultFormatter = response => { | ||
if (!response.ok) { | ||
throw Error(response.statusText); | ||
} | ||
return response.json(); | ||
}; | ||
const fetchInstance = formatter => (path, options) => { | ||
@@ -17,0 +22,0 @@ return fetch(path, options).then((typeof formatter === "function" && formatter) || defaultFormatter); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17128
312
17