Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: src/components/AddOn/support/services/Plugin.helper.test.ts from Jest to Vitest #2740

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import PluginHelper from './Plugin.helper';
import { vi } from 'vitest';

/**
* This file contains unit tests for the PluginHelper component.
*
* The tests cover:
* - Verification that the class contains the required method definitions.
* - Correct functionality of the `generateLinks` method, including returning proper objects.
* - Proper behavior of the `fetchStore` method, including handling of mocked JSON responses.
* - Functionality of the `fetchInstalled` method, verifying it returns the expected JSON data.
*
* These tests use Vitest for test execution and mock the global `fetch` function for asynchronous tests.
*/

describe('Testing src/components/AddOn/support/services/Plugin.helper.ts', () => {
test('Class should contain the required method definitions', () => {
it('Class should contain the required method definitions', () => {
const pluginHelper = new PluginHelper();
expect(pluginHelper).toHaveProperty('fetchStore');
expect(pluginHelper).toHaveProperty('fetchInstalled');
expect(pluginHelper).toHaveProperty('generateLinks');
expect(pluginHelper).toHaveProperty('generateLinks');
});
test('generateLinks should return proper objects', () => {
it('generateLinks should return proper objects', () => {
const obj = {
enabled: true,
name: 'demo',
Expand All @@ -28,9 +41,9 @@ describe('Testing src/components/AddOn/support/services/Plugin.helper.ts', () =>
});
it('fetchStore should return expected JSON', async () => {
const helper = new PluginHelper();
const spy = jest.spyOn(global, 'fetch').mockImplementation(() => {
const spy = vi.spyOn(global, 'fetch').mockImplementation(() => {
const response = new Response();
response.json = jest
response.json = vi
.fn()
.mockReturnValue(Promise.resolve({ data: 'mock data' }));
return Promise.resolve(response);
Expand All @@ -46,11 +59,11 @@ describe('Testing src/components/AddOn/support/services/Plugin.helper.ts', () =>
{ name: 'plugin1', component: 'Component1', enabled: true },
{ name: 'plugin2', component: 'Component2', enabled: false },
];
jest.spyOn(global, 'fetch').mockImplementation(() => {
vi.spyOn(global, 'fetch').mockImplementation(() => {
const response = new Response();
response.json = jest.fn().mockReturnValue(Promise.resolve(mockResponse));
response.json = vi.fn().mockReturnValue(Promise.resolve(mockResponse));
return Promise.resolve(response);
}) as jest.Mock;
});
const result = await pluginHelper.fetchInstalled();
expect(result).toEqual(mockResponse);
});
Expand Down
Loading