From 52b1114b595728b0005f5d12966234a497ff87cd Mon Sep 17 00:00:00 2001 From: zuies Date: Thu, 14 Sep 2023 15:56:33 +0300 Subject: [PATCH] mock router in test cases --- package-lock.json | 16 ++++++++++++++++ package.json | 1 + .../pages/statistics/Onboarding.spec.tsx | 1 + .../activeMembers/ActiveMemberBreakdown.spec.tsx | 1 + ...isengagedMembersCompositionBreakdown.spec.tsx | 1 + .../OnboardingMembersBreakdown.spec.tsx | 1 + 6 files changed, 21 insertions(+) diff --git a/package-lock.json b/package-lock.json index 9709f409..4afdbb6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,6 +41,7 @@ "moment": "^2.29.4", "moment-timezone": "^0.5.38", "next": "13.0.2", + "next-router-mock": "^0.9.9", "papaparse": "^5.4.1", "prettier": "^2.8.2", "react": "^18.2.0", @@ -9613,6 +9614,15 @@ } } }, + "node_modules/next-router-mock": { + "version": "0.9.9", + "resolved": "https://registry.npmjs.org/next-router-mock/-/next-router-mock-0.9.9.tgz", + "integrity": "sha512-2o50zr+5pWj0zzcvBEWNHDlmWmlDExPdX5OuXKW2aCxV85XUA6MlELr0n0f0wtXj5dUVZ8qspHj6YwF7KZHrbA==", + "peerDependencies": { + "next": ">=10.0.0", + "react": ">=17.0.0" + } + }, "node_modules/next/node_modules/postcss": { "version": "8.4.14", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz", @@ -19142,6 +19152,12 @@ } } }, + "next-router-mock": { + "version": "0.9.9", + "resolved": "https://registry.npmjs.org/next-router-mock/-/next-router-mock-0.9.9.tgz", + "integrity": "sha512-2o50zr+5pWj0zzcvBEWNHDlmWmlDExPdX5OuXKW2aCxV85XUA6MlELr0n0f0wtXj5dUVZ8qspHj6YwF7KZHrbA==", + "requires": {} + }, "ngraph.events": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/ngraph.events/-/ngraph.events-1.2.2.tgz", diff --git a/package.json b/package.json index f3b65d94..28b6dfe6 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "moment": "^2.29.4", "moment-timezone": "^0.5.38", "next": "13.0.2", + "next-router-mock": "^0.9.9", "papaparse": "^5.4.1", "prettier": "^2.8.2", "react": "^18.2.0", diff --git a/src/components/pages/statistics/Onboarding.spec.tsx b/src/components/pages/statistics/Onboarding.spec.tsx index e140efa7..3cce1606 100644 --- a/src/components/pages/statistics/Onboarding.spec.tsx +++ b/src/components/pages/statistics/Onboarding.spec.tsx @@ -1,6 +1,7 @@ import { render, screen } from '@testing-library/react'; import Onboarding from './Onboarding'; import { communityActiveDates } from '../../../lib/data/dateRangeValues'; +jest.mock('next/router', () => require('next-router-mock')); describe('Onboarding component', () => { const mockActivePeriod = 1; diff --git a/src/components/pages/statistics/memberBreakdowns/activeMembers/ActiveMemberBreakdown.spec.tsx b/src/components/pages/statistics/memberBreakdowns/activeMembers/ActiveMemberBreakdown.spec.tsx index 1d21b973..e175707b 100644 --- a/src/components/pages/statistics/memberBreakdowns/activeMembers/ActiveMemberBreakdown.spec.tsx +++ b/src/components/pages/statistics/memberBreakdowns/activeMembers/ActiveMemberBreakdown.spec.tsx @@ -1,5 +1,6 @@ import { render, screen } from '@testing-library/react'; import ActiveMemberBreakdown from './ActiveMemberBreakdown'; +jest.mock('next/router', () => require('next-router-mock')); describe('ActiveMemberBreakdown', () => { it('renders the component', () => { diff --git a/src/components/pages/statistics/memberBreakdowns/disengagedMembersComposition/DisengagedMembersCompositionBreakdown.spec.tsx b/src/components/pages/statistics/memberBreakdowns/disengagedMembersComposition/DisengagedMembersCompositionBreakdown.spec.tsx index 5d0ca59f..1ec85f55 100644 --- a/src/components/pages/statistics/memberBreakdowns/disengagedMembersComposition/DisengagedMembersCompositionBreakdown.spec.tsx +++ b/src/components/pages/statistics/memberBreakdowns/disengagedMembersComposition/DisengagedMembersCompositionBreakdown.spec.tsx @@ -1,5 +1,6 @@ import { render, screen } from '@testing-library/react'; import DisengagedMembersCompositionBreakdown from './DisengagedMembersCompositionBreakdown'; +jest.mock('next/router', () => require('next-router-mock')); describe('ActiveMemberBreakdown', () => { it('renders the component', () => { diff --git a/src/components/pages/statistics/memberBreakdowns/onboardingMembers/OnboardingMembersBreakdown.spec.tsx b/src/components/pages/statistics/memberBreakdowns/onboardingMembers/OnboardingMembersBreakdown.spec.tsx index 4053135f..34274109 100644 --- a/src/components/pages/statistics/memberBreakdowns/onboardingMembers/OnboardingMembersBreakdown.spec.tsx +++ b/src/components/pages/statistics/memberBreakdowns/onboardingMembers/OnboardingMembersBreakdown.spec.tsx @@ -1,5 +1,6 @@ import { render, screen } from '@testing-library/react'; import OnboardingMembersBreakdown from './OnboardingMembersBreakdown'; +jest.mock('next/router', () => require('next-router-mock')); describe('ActiveMemberBreakdown', () => { it('renders the component', () => {