Skip to content

Commit

Permalink
replace jest with vi
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalesi committed Oct 24, 2023
1 parent eb1f942 commit 232589a
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/shared/organisms/DataPanel/DataPanel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
resourceWithDistributionArray,
resourceWithoutDistrition,
} from 'shared/utils/__mocks__/data_panel_download_resource';
import { vi as jest } from 'vitest';

const mockNexus = createNexusClient({
uri: 'https://localhost',
fetch: {},
Expand All @@ -26,7 +26,7 @@ const mockParsedDataFromUrl: ParsedNexusUrl = {

describe('DataPanel', () => {
it('throws errors when create archive endpoint throws', async () => {
mockNexus.Resource.get = jest
mockNexus.Resource.get = vi
.fn()
.mockResolvedValue(resourceWithoutDistrition);
const mockEndpointError = new Error('Test Mock Error');
Expand All @@ -49,7 +49,7 @@ describe('DataPanel', () => {
});

it('does not contain warnings if all resources were found but archive create failed', async () => {
mockNexus.Resource.get = jest
mockNexus.Resource.get = vi
.fn()
.mockResolvedValue(resourceWithoutDistrition);
const mockEndpointError = new Error('Test Mock Error');
Expand All @@ -70,7 +70,7 @@ describe('DataPanel', () => {
});

it('contains warnings for each resource not found when archive creation failed', async () => {
mockNexus.Resource.get = jest
mockNexus.Resource.get = vi
.fn()
.mockResolvedValueOnce(resourceWithoutDistrition)
.mockRejectedValueOnce(new Error('Mock resource 2 not found'))
Expand Down Expand Up @@ -98,11 +98,11 @@ describe('DataPanel', () => {
});

it('throws errors when archive get endpoint failed', async () => {
mockNexus.Resource.get = jest
mockNexus.Resource.get = vi
.fn()
.mockResolvedValue(resourceWithoutDistrition);

mockNexus.Archive.create = jest
mockNexus.Archive.create = vi
.fn()
.mockResolvedValue('Archive create passed');
const mockEndpointError = new Error('However, Archive get failed');
Expand Down Expand Up @@ -130,13 +130,13 @@ describe('DataPanel', () => {
});

it('contains warnings for each resource not found when archive fetching failed', async () => {
mockNexus.Resource.get = jest
mockNexus.Resource.get = vi
.fn()
.mockResolvedValueOnce(resourceWithoutDistrition)
.mockRejectedValueOnce(new Error('Mock resource 2 not found'))
.mockRejectedValueOnce(new Error('Mock resource 3 not found'));

mockNexus.Archive.create = jest
mockNexus.Archive.create = vi
.fn()
.mockResolvedValue('Archive create passed');
const mockEndpointError = new Error('However, Archive get failed');
Expand Down Expand Up @@ -164,11 +164,11 @@ describe('DataPanel', () => {
});

it('does not throw if neither archive create nor archive fetch failed', async () => {
mockNexus.Resource.get = jest
mockNexus.Resource.get = vi
.fn()
.mockResolvedValue(resourceWithoutDistrition);

mockNexus.Archive.create = jest
mockNexus.Archive.create = vi
.fn()
.mockResolvedValue('Archive create passed');
mockNexus.httpGet = vi.fn().mockResolvedValue(new Blob());
Expand All @@ -191,13 +191,13 @@ describe('DataPanel', () => {
});

it('does not throw but contains warnings if some resources were not found but archive creation passed', async () => {
mockNexus.Resource.get = jest
mockNexus.Resource.get = vi
.fn()
.mockResolvedValue(resourceWithoutDistrition)
.mockRejectedValueOnce(new Error('Mock resource 2 not found'))
.mockRejectedValueOnce(new Error('Mock resource 3 not found'));

mockNexus.Archive.create = jest
mockNexus.Archive.create = vi
.fn()
.mockResolvedValue('Archive create passed');
mockNexus.httpGet = vi.fn().mockResolvedValue(new Blob());
Expand All @@ -220,10 +220,10 @@ describe('DataPanel', () => {
});

it('contains warnings for every distributions within resources that could not be fetched', async () => {
mockNexus.Resource.get = jest
mockNexus.Resource.get = vi
.fn()
.mockResolvedValue(resourceWithDistributionArray); // resource with 4 distributions
mockNexus.httpGet = jest
mockNexus.httpGet = vi
.fn()
// Out of 4 distributions, 2 were not fetched
.mockRejectedValueOnce(new Error('Distribution 1 could not be found')) // Error for 1st distribution
Expand All @@ -232,7 +232,7 @@ describe('DataPanel', () => {
.mockReturnValueOnce(getMockDistribution('mockfilename')) // Successful response for 4th distribution
.mockResolvedValueOnce(new Blob()); // Successful response for get archive

mockNexus.Archive.create = jest
mockNexus.Archive.create = vi
.fn()
.mockResolvedValue('Archive create passed');

Expand Down

0 comments on commit 232589a

Please sign in to comment.