Updated test libs

This commit is contained in:
Alejandro Celaya
2021-10-31 12:07:38 +01:00
parent 1486d1fba5
commit 80f0f9bd08
5 changed files with 3593 additions and 11549 deletions

View File

@@ -9,9 +9,8 @@ describe('<ImportServersBtn />', () => {
let wrapper: ShallowWrapper;
const onImportMock = jest.fn();
const createServersMock = jest.fn();
const serversImporterMock = Mock.of<ServersImporter>({
importServersFromFile: jest.fn().mockResolvedValue([]),
});
const importServersFromFile = jest.fn().mockResolvedValue([]);
const serversImporterMock = Mock.of<ServersImporter>({ importServersFromFile });
const click = jest.fn();
const fileRef = {
current: Mock.of<HTMLInputElement>({ click }),
@@ -76,17 +75,14 @@ describe('<ImportServersBtn />', () => {
expect(click).toHaveBeenCalledTimes(1);
});
it('imports servers when file input changes', (done) => {
it('imports servers when file input changes', async () => {
const wrapper = createWrapper();
const file = wrapper.find('.import-servers-btn__csv-select');
file.simulate('change', { target: { files: [ '' ] } });
await file.simulate('change', { target: { files: [ '' ] } }); // eslint-disable-line @typescript-eslint/await-thenable
setImmediate(() => {
expect(serversImporterMock.importServersFromFile).toHaveBeenCalledTimes(1);
expect(createServersMock).toHaveBeenCalledTimes(1);
expect(onImportMock).toHaveBeenCalledTimes(1);
done();
});
expect(importServersFromFile).toHaveBeenCalledTimes(1);
expect(createServersMock).toHaveBeenCalledTimes(1);
expect(onImportMock).toHaveBeenCalledTimes(1);
});
});

View File

@@ -4,7 +4,7 @@ import { fetchServers } from '../../../src/servers/reducers/remoteServers';
import { CREATE_SERVERS } from '../../../src/servers/reducers/servers';
describe('remoteServersReducer', () => {
afterEach(jest.resetAllMocks);
afterEach(jest.clearAllMocks);
describe('fetchServers', () => {
const get = jest.fn();
@@ -46,12 +46,12 @@ describe('remoteServersReducer', () => {
],
[ Promise.resolve('<html></html>'), {}],
[ Promise.reject({}), {}],
])('tries to fetch servers from remote', async (mockedValue, expectedList) => {
get.mockReturnValue(mockedValue);
])('tries to fetch servers from remote', async (mockedValue, expectedNewServers) => {
get.mockResolvedValue(mockedValue);
await fetchServers(axios)()(dispatch);
expect(dispatch).toHaveBeenCalledWith({ type: CREATE_SERVERS, newServers: expectedList });
expect(dispatch).toHaveBeenCalledWith({ type: CREATE_SERVERS, newServers: expectedNewServers });
expect(get).toHaveBeenCalledTimes(1);
});
});