Uninstalled jest-each and replaced by jest's native each

This commit is contained in:
Alejandro Celaya
2020-02-17 18:21:52 +01:00
parent da54a72b3e
commit d0f458bece
15 changed files with 30 additions and 45 deletions

View File

@@ -1,6 +1,5 @@
import React from 'react';
import { shallow } from 'enzyme';
import each from 'jest-each';
import searchBarCreator from '../../src/short-urls/SearchBar';
import SearchField from '../../src/utils/SearchField';
import Tag from '../../src/tags/helpers/Tag';
@@ -62,7 +61,7 @@ describe('<SearchBar />', () => {
expect(listShortUrlsMock).toHaveBeenCalledTimes(1);
});
each([ 'startDateChange', 'endDateChange' ]).it('updates short URLs list when date range changes', (event) => {
it.each([ 'startDateChange', 'endDateChange' ])('updates short URLs list when date range changes', (event) => {
wrapper = shallow(
<SearchBar shortUrlsListParams={{}} listShortUrls={listShortUrlsMock} />
);

View File

@@ -1,7 +1,6 @@
import React from 'react';
import { shallow } from 'enzyme';
import { identity } from 'ramda';
import each from 'jest-each';
import DeleteShortUrlModal from '../../../src/short-urls/helpers/DeleteShortUrlModal';
describe('<DeleteShortUrlModal />', () => {
@@ -32,7 +31,7 @@ describe('<DeleteShortUrlModal />', () => {
deleteShortUrl.mockClear();
});
each([
it.each([
[
{ error: 'INVALID_SHORTCODE_DELETION' },
'This short URL has received too many visits, and therefore, it cannot be deleted.',
@@ -49,7 +48,7 @@ describe('<DeleteShortUrlModal />', () => {
{ type: 'INVALID_SHORTCODE_DELETION', threshold: 8 },
'This short URL has received more than 8 visits, and therefore, it cannot be deleted.',
],
]).it('shows threshold error message when threshold error occurs', (errorData, expectedMessage) => {
])('shows threshold error message when threshold error occurs', (errorData, expectedMessage) => {
const wrapper = createWrapper({
loading: false,
error: true,

View File

@@ -1,7 +1,6 @@
import React from 'react';
import { shallow } from 'enzyme';
import { FormGroup, Modal, ModalHeader } from 'reactstrap';
import each from 'jest-each';
import EditMetaModal from '../../../src/short-urls/helpers/EditMetaModal';
describe('<EditMetaModal />', () => {
@@ -40,10 +39,10 @@ describe('<EditMetaModal />', () => {
expect(error).toHaveLength(0);
});
each([
it.each([
[ true, 'Saving...' ],
[ false, 'Save' ],
]).it('renders submit button on expected state', (saving, expectedText) => {
])('renders submit button on expected state', (saving, expectedText) => {
const wrapper = createWrapper({}, { saving, error: false, meta: {} });
const button = wrapper.find('[type="submit"]');
@@ -69,11 +68,11 @@ describe('<EditMetaModal />', () => {
expect(editShortUrlMeta).toHaveBeenCalled();
});
each([
it.each([
[ '.btn-link', 'onClick' ],
[ Modal, 'toggle' ],
[ ModalHeader, 'toggle' ],
]).it('resets meta when modal is toggled in any way', (componentToFind, propToCall) => {
])('resets meta when modal is toggled in any way', (componentToFind, propToCall) => {
const wrapper = createWrapper({}, { saving: false, error: false, meta: {} });
const component = wrapper.find(componentToFind);

View File

@@ -1,7 +1,6 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Modal } from 'reactstrap';
import each from 'jest-each';
import createEditTagsModal from '../../../src/short-urls/helpers/EditTagsModal';
describe('<EditTagsModal />', () => {
@@ -76,7 +75,7 @@ describe('<EditTagsModal />', () => {
expect(saveBtn.text()).toEqual('Saving tags...');
});
each([[ undefined ], [ null ], [ 'example.com' ]]).it('saves tags when save button is clicked', (domain, done) => {
it.each([[ undefined ], [ null ], [ 'example.com' ]])('saves tags when save button is clicked', (domain, done) => {
const wrapper = createWrapper({
shortCode,
tags: [],

View File

@@ -1,7 +1,6 @@
import React from 'react';
import { shallow } from 'enzyme';
import { UncontrolledTooltip } from 'reactstrap';
import each from 'jest-each';
import ShortUrlVisitsCount from '../../../src/short-urls/helpers/ShortUrlVisitsCount';
describe('<ShortUrlVisitsCount />', () => {
@@ -15,7 +14,7 @@ describe('<ShortUrlVisitsCount />', () => {
afterEach(() => wrapper && wrapper.unmount());
each([ undefined, {}]).it('just returns visits when no maxVisits is provided', (meta) => {
it.each([ undefined, {}])('just returns visits when no maxVisits is provided', (meta) => {
const visitsCount = 45;
const wrapper = createWrapper(visitsCount, { meta });
const maxVisitsHelper = wrapper.find('.short-urls-visits-count__max-visits-control');

View File

@@ -1,6 +1,5 @@
import React from 'react';
import { shallow } from 'enzyme';
import each from 'jest-each';
import { Link } from 'react-router-dom';
import VisitStatsLink from '../../../src/short-urls/helpers/VisitStatsLink';
@@ -9,14 +8,14 @@ describe('<VisitStatsLink />', () => {
afterEach(() => wrapper && wrapper.unmount());
each([
it.each([
[ undefined, undefined ],
[ null, null ],
[{}, null ],
[{}, undefined ],
[ null, {}],
[ undefined, {}],
]).it('only renders a plan span when either server or short URL are not set', (selectedServer, shortUrl) => {
])('only renders a plan span when either server or short URL are not set', (selectedServer, shortUrl) => {
wrapper = shallow(<VisitStatsLink selectedServer={selectedServer} shortUrl={shortUrl}>Something</VisitStatsLink>);
const link = wrapper.find(Link);
@@ -24,14 +23,14 @@ describe('<VisitStatsLink />', () => {
expect(wrapper.html()).toEqual('<span>Something</span>');
});
each([
it.each([
[{ id: '1' }, { shortCode: 'abc123' }, '/server/1/short-code/abc123/visits' ],
[
{ id: '3' },
{ shortCode: 'def456', domain: 'example.com' },
'/server/3/short-code/def456/visits?domain=example.com',
],
]).it('renders link with expected query when', (selectedServer, shortUrl, expectedLink) => {
])('renders link with expected query when', (selectedServer, shortUrl, expectedLink) => {
wrapper = shallow(<VisitStatsLink selectedServer={selectedServer} shortUrl={shortUrl}>Something</VisitStatsLink>);
const link = wrapper.find(Link);
const to = link.prop('to');

View File

@@ -1,4 +1,3 @@
import each from 'jest-each';
import reducer, {
DELETE_SHORT_URL_ERROR,
DELETE_SHORT_URL_START,
@@ -60,9 +59,9 @@ describe('shortUrlDeletionReducer', () => {
getState.mockClear();
});
each(
it.each(
[[ undefined ], [ null ], [ 'example.com' ]]
).it('dispatches proper actions if API client request succeeds', async (domain) => {
)('dispatches proper actions if API client request succeeds', async (domain) => {
const apiClientMock = {
deleteShortUrl: jest.fn(() => ''),
};

View File

@@ -1,5 +1,4 @@
import moment from 'moment';
import each from 'jest-each';
import reducer, {
EDIT_SHORT_URL_META_START,
EDIT_SHORT_URL_META_ERROR,
@@ -57,7 +56,7 @@ describe('shortUrlMetaReducer', () => {
afterEach(jest.clearAllMocks);
each([[ undefined ], [ null ], [ 'example.com' ]]).it('dispatches metadata on success', async (domain) => {
it.each([[ undefined ], [ null ], [ 'example.com' ]])('dispatches metadata on success', async (domain) => {
await editShortUrlMeta(buildShlinkApiClient)(shortCode, domain, meta)(dispatch);
expect(buildShlinkApiClient).toHaveBeenCalledTimes(1);

View File

@@ -1,4 +1,3 @@
import each from 'jest-each';
import reducer, {
EDIT_SHORT_URL_TAGS_ERROR,
EDIT_SHORT_URL_TAGS_START,
@@ -61,7 +60,7 @@ describe('shortUrlTagsReducer', () => {
dispatch.mockReset();
});
each([[ undefined ], [ null ], [ 'example.com' ]]).it('dispatches normalized tags on success', async (domain) => {
it.each([[ undefined ], [ null ], [ 'example.com' ]])('dispatches normalized tags on success', async (domain) => {
const normalizedTags = [ 'bar', 'foo' ];
updateShortUrlTags.mockResolvedValue(normalizedTags);