Skip to content

Commit 652d6de

Browse files
author
stevegalili
committed
Fix tune TS errors
1 parent d105659 commit 652d6de

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

examples/cookbook/app/network-requests/PhoneBook.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export default () => {
2525
try {
2626
await Promise.all([_getAllContacts(), _getAllFavorites()]);
2727
} catch (e) {
28-
setError(e.message);
28+
const message = e instanceof Error ? e.message : JSON.stringify(e);
29+
setError(message);
2930
}
3031
};
3132

examples/cookbook/app/network-requests/__tests__/PhoneBook.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jest.mock('axios');
88

99
describe('PhoneBook', () => {
1010
it('fetches contacts successfully and renders in list', async () => {
11-
(global.fetch as jest.SpyInstance).mockResolvedValueOnce({
11+
(global.fetch as jest.Mock).mockResolvedValueOnce({
1212
ok: true,
1313
json: jest.fn().mockResolvedValueOnce(DATA),
1414
});
@@ -22,7 +22,7 @@ describe('PhoneBook', () => {
2222
});
2323

2424
it('fails to fetch contacts and renders error message', async () => {
25-
(global.fetch as jest.SpyInstance).mockResolvedValueOnce({
25+
(global.fetch as jest.Mock).mockResolvedValueOnce({
2626
ok: false,
2727
});
2828
(axios.get as jest.Mock).mockResolvedValue({ data: DATA });
@@ -33,7 +33,7 @@ describe('PhoneBook', () => {
3333
});
3434

3535
it('fetches favorites successfully and renders all users avatars', async () => {
36-
(global.fetch as jest.SpyInstance).mockResolvedValueOnce({
36+
(global.fetch as jest.Mock).mockResolvedValueOnce({
3737
ok: true,
3838
json: jest.fn().mockResolvedValueOnce(DATA),
3939
});
@@ -46,7 +46,7 @@ describe('PhoneBook', () => {
4646
});
4747

4848
it('fails to fetch favorites and renders error message', async () => {
49-
(global.fetch as jest.SpyInstance).mockResolvedValueOnce({
49+
(global.fetch as jest.Mock).mockResolvedValueOnce({
5050
ok: true,
5151
json: jest.fn().mockResolvedValueOnce(DATA),
5252
});

website/docs/12.x/cookbook/network-requests/fetch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ See MDN's [docs](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Usin
199199
...
200200
it('fails to fetch contacts and renders error message', async () => {
201201
// mock the fetch function to be not ok which will throw an error
202-
(global.fetch as jest.SpyInstance).mockResolvedValueOnce({
202+
(global.fetch as jest.Mock).mockResolvedValueOnce({
203203
ok: false,
204204
});
205205
render(<PhoneBook/>);

0 commit comments

Comments
 (0)