mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-10 09:33:51 +00:00
Replaced unmaintained dependency
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { CsvJson } from 'csvjson';
|
||||
import ServersExporter from '../../../src/servers/services/ServersExporter';
|
||||
import LocalStorage from '../../../src/utils/services/LocalStorage';
|
||||
import { appendChild, removeChild, windowMock } from '../../mocks/WindowMock';
|
||||
@@ -22,9 +21,7 @@ describe('ServersExporter', () => {
|
||||
const erroneousToCsv = jest.fn(() => {
|
||||
throw new Error('');
|
||||
});
|
||||
const createCsvjsonMock = (throwError = false) => Mock.of<CsvJson>({
|
||||
toCSV: throwError ? erroneousToCsv : jest.fn(() => ''),
|
||||
});
|
||||
const createCsvjsonMock = (throwError = false) => (throwError ? erroneousToCsv : jest.fn(() => ''));
|
||||
|
||||
beforeEach(jest.clearAllMocks);
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { CsvJson } from 'csvjson';
|
||||
import { ServersImporter } from '../../../src/servers/services/ServersImporter';
|
||||
import { RegularServer } from '../../../src/servers/data';
|
||||
|
||||
describe('ServersImporter', () => {
|
||||
const servers: RegularServer[] = [Mock.all<RegularServer>(), Mock.all<RegularServer>()];
|
||||
const toObject = jest.fn().mockReturnValue(servers);
|
||||
const csvjsonMock = Mock.of<CsvJson>({ toObject });
|
||||
const csvjsonMock = jest.fn().mockResolvedValue(servers);
|
||||
const readAsText = jest.fn();
|
||||
const fileReaderMock = Mock.of<FileReader>({
|
||||
readAsText,
|
||||
@@ -28,9 +26,7 @@ describe('ServersImporter', () => {
|
||||
it('rejects with error if parsing the file fails', async () => {
|
||||
const expectedError = new Error('Error parsing file');
|
||||
|
||||
toObject.mockImplementation(() => {
|
||||
throw expectedError;
|
||||
});
|
||||
csvjsonMock.mockRejectedValue(expectedError);
|
||||
|
||||
await expect(importer.importServersFromFile(Mock.of<File>({ type: 'text/html' }))).rejects.toEqual(expectedError);
|
||||
});
|
||||
@@ -59,7 +55,7 @@ describe('ServersImporter', () => {
|
||||
],
|
||||
],
|
||||
])('rejects with error if provided file does not parse to valid list of servers', async (parsedObject) => {
|
||||
toObject.mockReturnValue(parsedObject);
|
||||
csvjsonMock.mockResolvedValue(parsedObject);
|
||||
|
||||
await expect(importer.importServersFromFile(Mock.of<File>({ type: 'text/html' }))).rejects.toEqual(
|
||||
new Error('Provided file does not have the right format.'),
|
||||
@@ -80,13 +76,13 @@ describe('ServersImporter', () => {
|
||||
},
|
||||
];
|
||||
|
||||
toObject.mockReturnValue(expectedServers);
|
||||
csvjsonMock.mockResolvedValue(expectedServers);
|
||||
|
||||
const result = await importer.importServersFromFile(Mock.all<File>());
|
||||
|
||||
expect(result).toEqual(expectedServers);
|
||||
expect(readAsText).toHaveBeenCalledTimes(1);
|
||||
expect(toObject).toHaveBeenCalledTimes(1);
|
||||
expect(csvjsonMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user