Skip to content

Commit

Permalink
upgrade-package-reacti18next (#2229)
Browse files Browse the repository at this point in the history
  • Loading branch information
Suswetha6 authored Aug 27, 2024
1 parent 75d2e55 commit 6e51fc0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"react-datepicker": "^7.3.0",
"react-dom": "^17.0.2",
"react-google-recaptcha": "^3.1.0",
"react-i18next": "^11.18.1",
"react-i18next": "^12.3.1",
"react-icons": "^5.2.1",
"react-infinite-scroll-component": "^6.1.0",
"react-multi-carousel": "^2.8.5",
Expand Down
8 changes: 5 additions & 3 deletions src/utils/errorHandler.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { TFunction } from 'react-i18next';
type TFunction = (key: string, options?: Record<string, unknown>) => string;

import { errorHandler } from './errorHandler';
import { toast } from 'react-toastify';

Expand All @@ -9,8 +10,9 @@ jest.mock('react-toastify', () => ({
}));

describe('Test if errorHandler is working properly', () => {
const t: TFunction<'translation', string> = (key: string) => key;
const tErrors: TFunction<'errors', string> = (key: string) => key;
const t: TFunction = (key: string) => key;
const tErrors: TFunction = (key: string, options?: Record<string, unknown>) =>
key;

it('should call toast.error with the correct message if error message is "Failed to fetch"', () => {
const error = new Error('Failed to fetch');
Expand Down
8 changes: 3 additions & 5 deletions src/utils/errorHandler.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { TFunction } from 'react-i18next';
type TFunction = (key: string, options?: Record<string, unknown>) => string;

import { toast } from 'react-toastify';
import i18n from './i18n';
/**
Expand All @@ -7,10 +8,7 @@ import i18n from './i18n';
If the error is due to the Talawa API being unavailable, it displays a custom message.
*/
export const errorHandler = (a: unknown, error: unknown): void => {
const tErrors = i18n.getFixedT(
null,
'errors',
) as unknown as TFunction<string>;
const tErrors: TFunction = i18n.getFixedT(null, 'errors');
if (error instanceof Error) {
switch (error.message) {
case 'Failed to fetch':
Expand Down

0 comments on commit 6e51fc0

Please sign in to comment.