From 70f60e447a9825f4d3201be0b2743f711f82344b Mon Sep 17 00:00:00 2001 From: adithya Date: Wed, 27 Nov 2024 11:55:20 +0530 Subject: [PATCH 1/2] Migrated to vitest --- .../support/components/Action/Action.spec.tsx | 25 +++++++++++++++++++ vitest.config.ts | 3 ++- vitest.setup.ts | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/components/AddOn/support/components/Action/Action.spec.tsx create mode 100644 vitest.setup.ts diff --git a/src/components/AddOn/support/components/Action/Action.spec.tsx b/src/components/AddOn/support/components/Action/Action.spec.tsx new file mode 100644 index 0000000000..df305b4a14 --- /dev/null +++ b/src/components/AddOn/support/components/Action/Action.spec.tsx @@ -0,0 +1,25 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import { Provider } from 'react-redux'; +import { describe, test, expect } from 'vitest'; // Import from Vitest + +import { store } from 'state/store'; +import Action from './Action'; + +describe('Testing Action Component', () => { + const props = { + children: 'dummy children', + label: 'dummy label', + }; + + test('should render props and text elements for the page component', () => { + const { getByText } = render( + + + , + ); + + expect(getByText(props.label)).toBeInTheDocument(); + expect(getByText(props.children)).toBeInTheDocument(); + }); +}); diff --git a/vitest.config.ts b/vitest.config.ts index cd08488b3c..ad85276111 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'vite'; +import { defineConfig } from 'vitest/config'; import react from '@vitejs/plugin-react'; import { nodePolyfills } from 'vite-plugin-node-polyfills'; import tsconfigPaths from 'vite-tsconfig-paths'; @@ -15,6 +15,7 @@ export default defineConfig({ include: ['src/**/*.spec.{js,jsx,ts,tsx}'], globals: true, environment: 'jsdom', + setupFiles: 'vitest.setup.ts', coverage: { enabled: true, provider: 'istanbul', diff --git a/vitest.setup.ts b/vitest.setup.ts new file mode 100644 index 0000000000..7b0828bfa8 --- /dev/null +++ b/vitest.setup.ts @@ -0,0 +1 @@ +import '@testing-library/jest-dom'; From bb70edbc5980d313a2c3bf6f21add0d15b4ee986 Mon Sep 17 00:00:00 2001 From: adithya Date: Wed, 27 Nov 2024 14:11:17 +0530 Subject: [PATCH 2/2] Added ts-doc comment --- .../AddOn/support/components/Action/Action.spec.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/AddOn/support/components/Action/Action.spec.tsx b/src/components/AddOn/support/components/Action/Action.spec.tsx index df305b4a14..e0682a5645 100644 --- a/src/components/AddOn/support/components/Action/Action.spec.tsx +++ b/src/components/AddOn/support/components/Action/Action.spec.tsx @@ -1,7 +1,13 @@ +/** + * Unit tests for the Action component. + * + * This file contains tests for the Action component to ensure it behaves as expected + * under various scenarios. + */ import React from 'react'; import { render } from '@testing-library/react'; import { Provider } from 'react-redux'; -import { describe, test, expect } from 'vitest'; // Import from Vitest +import { describe, test, expect } from 'vitest'; import { store } from 'state/store'; import Action from './Action';