Commit 7fd1a1ff authored by Vitaly Slobodin's avatar Vitaly Slobodin

Fix ESLint errors in frontend specs

Before enabling @gitlab/eslint-plugin@3.0.0 with our Jest config
we should be sure that all ESLint errors have been fixed.
parent a1b3a364
...@@ -30,7 +30,6 @@ describe('Productivity analytics filter getters', () => { ...@@ -30,7 +30,6 @@ describe('Productivity analytics filter getters', () => {
}; };
}); });
/*
describe('when chart is not scatterplot', () => { describe('when chart is not scatterplot', () => {
it('returns an object with common filter params', () => { it('returns an object with common filter params', () => {
const expected = { const expected = {
...@@ -48,7 +47,6 @@ describe('Productivity analytics filter getters', () => { ...@@ -48,7 +47,6 @@ describe('Productivity analytics filter getters', () => {
expect(result).toEqual(expected); expect(result).toEqual(expected);
}); });
}); });
*/
describe('when chart is scatterplot', () => { describe('when chart is scatterplot', () => {
it('returns an object with common filter params and subtracts 30 days from the merged_after date', () => { it('returns an object with common filter params and subtracts 30 days from the merged_after date', () => {
......
...@@ -67,8 +67,6 @@ describe('Design management list item component', () => { ...@@ -67,8 +67,6 @@ describe('Design management list item component', () => {
image = wrapper.find('img'); image = wrapper.find('img');
glIntersectionObserver = wrapper.find(GlIntersectionObserver); glIntersectionObserver = wrapper.find(GlIntersectionObserver);
expect(image.attributes('src')).toBe('');
glIntersectionObserver.vm.$emit('appear'); glIntersectionObserver.vm.$emit('appear');
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
......
...@@ -140,7 +140,7 @@ describe('ee/ide/lib/mirror', () => { ...@@ -140,7 +140,7 @@ describe('ee/ide/lib/mirror', () => {
beforeEach(connectFail); beforeEach(connectFail);
it('rejects with error', () => { it('rejects with error', () => {
expect(connection).rejects.toEqual(new Error(MSG_CONNECTION_ERROR)); return expect(connection).rejects.toEqual(new Error(MSG_CONNECTION_ERROR));
}); });
}); });
}); });
......
...@@ -73,7 +73,7 @@ describe('ee/ide/stores/modules/terminal_sync/actions', () => { ...@@ -73,7 +73,7 @@ describe('ee/ide/stores/modules/terminal_sync/actions', () => {
const result = actions.start({ rootState: { terminal: { session } } }); const result = actions.start({ rootState: { terminal: { session } } });
expect(result).rejects.toBe(undefined); return expect(result).rejects.toBe(undefined);
}); });
describe('with terminal session in state', () => { describe('with terminal session in state', () => {
...@@ -106,11 +106,12 @@ describe('ee/ide/stores/modules/terminal_sync/actions', () => { ...@@ -106,11 +106,12 @@ describe('ee/ide/stores/modules/terminal_sync/actions', () => {
const result = actions.start({ rootState, commit }); const result = actions.start({ rootState, commit });
expect(result).rejects.toEqual(err); return Promise.all([
expect(result).rejects.toEqual(err),
return result.catch(() => { result.catch(() => {
expect(commit).toHaveBeenCalledWith(types.SET_ERROR, err); expect(commit).toHaveBeenCalledWith(types.SET_ERROR, err);
}); }),
]);
}); });
}); });
}); });
......
...@@ -46,10 +46,6 @@ describe('EE Sidebar store', () => { ...@@ -46,10 +46,6 @@ describe('EE Sidebar store', () => {
}); });
describe('setWeightData', () => { describe('setWeightData', () => {
beforeEach(() => {
expect(store.weight).toBe(null);
});
it('sets weight data', () => { it('sets weight data', () => {
const weight = 3; const weight = 3;
store.setWeightData({ store.setWeightData({
......
...@@ -45,6 +45,3 @@ describe('Clusters store actions', () => { ...@@ -45,6 +45,3 @@ describe('Clusters store actions', () => {
}); });
}); });
}); });
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
...@@ -55,6 +55,3 @@ describe('Contributors store actions', () => { ...@@ -55,6 +55,3 @@ describe('Contributors store actions', () => {
}); });
}); });
}); });
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
...@@ -74,6 +74,3 @@ describe('Contributors Store Getters', () => { ...@@ -74,6 +74,3 @@ describe('Contributors Store Getters', () => {
}); });
}); });
}); });
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
...@@ -75,7 +75,7 @@ describe('awsServicesFacade', () => { ...@@ -75,7 +75,7 @@ describe('awsServicesFacade', () => {
}); });
it('return list of regions where each item has a name and value', () => { it('return list of regions where each item has a name and value', () => {
expect(fetchRoles()).resolves.toEqual(rolesOutput); return expect(fetchRoles()).resolves.toEqual(rolesOutput);
}); });
}); });
...@@ -91,7 +91,7 @@ describe('awsServicesFacade', () => { ...@@ -91,7 +91,7 @@ describe('awsServicesFacade', () => {
}); });
it('return list of roles where each item has a name and value', () => { it('return list of roles where each item has a name and value', () => {
expect(fetchRegions()).resolves.toEqual(regionsOutput); return expect(fetchRegions()).resolves.toEqual(regionsOutput);
}); });
}); });
...@@ -112,7 +112,7 @@ describe('awsServicesFacade', () => { ...@@ -112,7 +112,7 @@ describe('awsServicesFacade', () => {
}); });
it('return list of key pairs where each item has a name and value', () => { it('return list of key pairs where each item has a name and value', () => {
expect(fetchKeyPairs({ region })).resolves.toEqual(keyPairsOutput); return expect(fetchKeyPairs({ region })).resolves.toEqual(keyPairsOutput);
}); });
}); });
...@@ -133,7 +133,7 @@ describe('awsServicesFacade', () => { ...@@ -133,7 +133,7 @@ describe('awsServicesFacade', () => {
}); });
it('return list of vpcs where each item has a name and value', () => { it('return list of vpcs where each item has a name and value', () => {
expect(fetchVpcs({ region })).resolves.toEqual(vpcsOutput); return expect(fetchVpcs({ region })).resolves.toEqual(vpcsOutput);
}); });
}); });
...@@ -151,7 +151,7 @@ describe('awsServicesFacade', () => { ...@@ -151,7 +151,7 @@ describe('awsServicesFacade', () => {
}); });
it('uses name tag value as the vpc name', () => { it('uses name tag value as the vpc name', () => {
expect(fetchVpcs({ region })).resolves.toEqual(vpcsOutput); return expect(fetchVpcs({ region })).resolves.toEqual(vpcsOutput);
}); });
}); });
...@@ -167,7 +167,7 @@ describe('awsServicesFacade', () => { ...@@ -167,7 +167,7 @@ describe('awsServicesFacade', () => {
}); });
it('return list of subnets where each item has a name and value', () => { it('return list of subnets where each item has a name and value', () => {
expect(fetchSubnets({ region, vpc })).resolves.toEqual(subnetsOutput); return expect(fetchSubnets({ region, vpc })).resolves.toEqual(subnetsOutput);
}); });
}); });
...@@ -189,7 +189,7 @@ describe('awsServicesFacade', () => { ...@@ -189,7 +189,7 @@ describe('awsServicesFacade', () => {
}); });
it('return list of security groups where each item has a name and value', () => { it('return list of security groups where each item has a name and value', () => {
expect(fetchSecurityGroups({ region, vpc })).resolves.toEqual(securityGroupsOutput); return expect(fetchSecurityGroups({ region, vpc })).resolves.toEqual(securityGroupsOutput);
}); });
}); });
}); });
...@@ -8,12 +8,13 @@ describe('Mock auto-injection', () => { ...@@ -8,12 +8,13 @@ describe('Mock auto-injection', () => {
failMock = jest.spyOn(global, 'fail').mockImplementation(); failMock = jest.spyOn(global, 'fail').mockImplementation();
}); });
it('~/lib/utils/axios_utils', done => { it('~/lib/utils/axios_utils', () => {
expect(axios.get('http://gitlab.com')).rejects.toThrow('Unexpected unmocked request'); return Promise.all([
setImmediate(() => { expect(axios.get('http://gitlab.com')).rejects.toThrow('Unexpected unmocked request'),
expect(failMock).toHaveBeenCalledTimes(1); setImmediate(() => {
done(); expect(failMock).toHaveBeenCalledTimes(1);
}); }),
]);
}); });
it('jQuery.ajax()', () => { it('jQuery.ajax()', () => {
......
...@@ -81,7 +81,8 @@ describe('DuplicateDashboardForm', () => { ...@@ -81,7 +81,8 @@ describe('DuplicateDashboardForm', () => {
it('with the inital form values', () => { it('with the inital form values', () => {
expect(wrapper.emitted().change).toHaveLength(1); expect(wrapper.emitted().change).toHaveLength(1);
expect(lastChange()).resolves.toEqual({
return expect(lastChange()).resolves.toEqual({
branch: '', branch: '',
commitMessage: expect.any(String), commitMessage: expect.any(String),
dashboard: dashboardGitResponse[0].path, dashboard: dashboardGitResponse[0].path,
...@@ -92,7 +93,7 @@ describe('DuplicateDashboardForm', () => { ...@@ -92,7 +93,7 @@ describe('DuplicateDashboardForm', () => {
it('containing an inputted file name', () => { it('containing an inputted file name', () => {
setValue('fileName', 'my_dashboard.yml'); setValue('fileName', 'my_dashboard.yml');
expect(lastChange()).resolves.toMatchObject({ return expect(lastChange()).resolves.toMatchObject({
fileName: 'my_dashboard.yml', fileName: 'my_dashboard.yml',
}); });
}); });
...@@ -100,7 +101,7 @@ describe('DuplicateDashboardForm', () => { ...@@ -100,7 +101,7 @@ describe('DuplicateDashboardForm', () => {
it('containing a default commit message when no message is set', () => { it('containing a default commit message when no message is set', () => {
setValue('commitMessage', ''); setValue('commitMessage', '');
expect(lastChange()).resolves.toMatchObject({ return expect(lastChange()).resolves.toMatchObject({
commitMessage: expect.stringContaining('Create custom dashboard'), commitMessage: expect.stringContaining('Create custom dashboard'),
}); });
}); });
...@@ -108,7 +109,7 @@ describe('DuplicateDashboardForm', () => { ...@@ -108,7 +109,7 @@ describe('DuplicateDashboardForm', () => {
it('containing an inputted commit message', () => { it('containing an inputted commit message', () => {
setValue('commitMessage', 'My commit message'); setValue('commitMessage', 'My commit message');
expect(lastChange()).resolves.toMatchObject({ return expect(lastChange()).resolves.toMatchObject({
commitMessage: expect.stringContaining('My commit message'), commitMessage: expect.stringContaining('My commit message'),
}); });
}); });
...@@ -116,7 +117,7 @@ describe('DuplicateDashboardForm', () => { ...@@ -116,7 +117,7 @@ describe('DuplicateDashboardForm', () => {
it('containing an inputted branch name', () => { it('containing an inputted branch name', () => {
setValue('branchName', 'a-new-branch'); setValue('branchName', 'a-new-branch');
expect(lastChange()).resolves.toMatchObject({ return expect(lastChange()).resolves.toMatchObject({
branch: 'a-new-branch', branch: 'a-new-branch',
}); });
}); });
...@@ -125,13 +126,14 @@ describe('DuplicateDashboardForm', () => { ...@@ -125,13 +126,14 @@ describe('DuplicateDashboardForm', () => {
setChecked(wrapper.vm.$options.radioVals.DEFAULT); setChecked(wrapper.vm.$options.radioVals.DEFAULT);
setValue('branchName', 'a-new-branch'); setValue('branchName', 'a-new-branch');
expect(lastChange()).resolves.toMatchObject({ return Promise.all([
branch: defaultBranch, expect(lastChange()).resolves.toMatchObject({
}); branch: defaultBranch,
}),
return wrapper.vm.$nextTick(() => { wrapper.vm.$nextTick(() => {
expect(findByRef('branchName').isVisible()).toBe(false); expect(findByRef('branchName').isVisible()).toBe(false);
}); }),
]);
}); });
it('when `new` branch option is chosen, focuses on the branch name input', () => { it('when `new` branch option is chosen, focuses on the branch name input', () => {
......
...@@ -212,13 +212,6 @@ describe.skip('Old Notes (~/notes.js)', () => { ...@@ -212,13 +212,6 @@ describe.skip('Old Notes (~/notes.js)', () => {
jest.spyOn($note, 'toggleClass'); jest.spyOn($note, 'toggleClass');
}); });
afterEach(() => {
expect(typeof urlUtility.getLocationHash.mock).toBe('object');
urlUtility.getLocationHash.mockRestore();
expect(urlUtility.getLocationHash.mock).toBeUndefined();
expect(urlUtility.getLocationHash()).toBeNull();
});
// urlUtility is a dependency of the notes module. Its getLocatinHash() method should be called internally. // urlUtility is a dependency of the notes module. Its getLocatinHash() method should be called internally.
it('sets target when hash matches', () => { it('sets target when hash matches', () => {
...@@ -629,48 +622,6 @@ describe.skip('Old Notes (~/notes.js)', () => { ...@@ -629,48 +622,6 @@ describe.skip('Old Notes (~/notes.js)', () => {
done(); done();
}); });
}); });
// This is a bad test carried over from the Karma -> Jest migration.
// The corresponding test in the Karma suite tests for
// elements and methods that don't actually exist, and gives a false
// positive pass.
/*
it('should show flash error message when comment failed to be updated', done => {
mockNotesPost();
jest.spyOn(notes, 'addFlash').mockName('addFlash');
$('.js-comment-button').click();
deferredPromise()
.then(() => {
const $noteEl = $notesContainer.find(`#note_${note.id}`);
$noteEl.find('.js-note-edit').click();
$noteEl.find('textarea.js-note-text').val(updatedComment);
mockNotesPostError();
$noteEl.find('.js-comment-save-button').click();
notes.updateComment({preventDefault: () => {}});
})
.then(() => deferredPromise())
.then(() => {
const $updatedNoteEl = $notesContainer.find(`#note_${note.id}`);
expect($updatedNoteEl.hasClass('.being-posted')).toEqual(false); // Remove being-posted visuals
expect(
$updatedNoteEl
.find('.note-text')
.text()
.trim(),
).toEqual(sampleComment); // See if comment reverted back to original
expect(notes.addFlash).toHaveBeenCalled();
expect(notes.flashContainer.style.display).not.toBe('none');
done();
})
.catch(done.fail);
}, 5000);
*/
}); });
describe('postComment with Slash commands', () => { describe('postComment with Slash commands', () => {
......
...@@ -143,7 +143,7 @@ describe('Release detail actions', () => { ...@@ -143,7 +143,7 @@ describe('Release detail actions', () => {
{ type: types.RECEIVE_UPDATE_RELEASE_SUCCESS }, { type: types.RECEIVE_UPDATE_RELEASE_SUCCESS },
])); ]));
describe('when the releaseShowPage feature flag is enabled', () => { it('redirects to the releases page if releaseShowPage feature flag is enabled', () => {
const rootState = { featureFlags: { releaseShowPage: true } }; const rootState = { featureFlags: { releaseShowPage: true } };
const updatedState = merge({}, state, { const updatedState = merge({}, state, {
releasesPagePath: 'path/to/releases/page', releasesPagePath: 'path/to/releases/page',
......
/* eslint-disable jest/valid-describe */
/*
* ESLint disable directive ↑ can be removed once
* https://github.com/jest-community/eslint-plugin-jest/issues/203
* is resolved
*/
import createState from '~/releases/stores/modules/detail/state'; import createState from '~/releases/stores/modules/detail/state';
import mutations from '~/releases/stores/modules/detail/mutations'; import mutations from '~/releases/stores/modules/detail/mutations';
import * as types from '~/releases/stores/modules/detail/mutation_types'; import * as types from '~/releases/stores/modules/detail/mutation_types';
...@@ -27,6 +20,7 @@ describe('Release detail mutations', () => { ...@@ -27,6 +20,7 @@ describe('Release detail mutations', () => {
release = convertObjectPropsToCamelCase(originalRelease); release = convertObjectPropsToCamelCase(originalRelease);
}); });
// eslint-disable-next-line jest/valid-describe
describe(types.REQUEST_RELEASE, () => { describe(types.REQUEST_RELEASE, () => {
it('set state.isFetchingRelease to true', () => { it('set state.isFetchingRelease to true', () => {
mutations[types.REQUEST_RELEASE](state); mutations[types.REQUEST_RELEASE](state);
...@@ -35,6 +29,7 @@ describe('Release detail mutations', () => { ...@@ -35,6 +29,7 @@ describe('Release detail mutations', () => {
}); });
}); });
// eslint-disable-next-line jest/valid-describe
describe(types.RECEIVE_RELEASE_SUCCESS, () => { describe(types.RECEIVE_RELEASE_SUCCESS, () => {
it('handles a successful response from the server', () => { it('handles a successful response from the server', () => {
mutations[types.RECEIVE_RELEASE_SUCCESS](state, release); mutations[types.RECEIVE_RELEASE_SUCCESS](state, release);
...@@ -49,6 +44,7 @@ describe('Release detail mutations', () => { ...@@ -49,6 +44,7 @@ describe('Release detail mutations', () => {
}); });
}); });
// eslint-disable-next-line jest/valid-describe
describe(types.RECEIVE_RELEASE_ERROR, () => { describe(types.RECEIVE_RELEASE_ERROR, () => {
it('handles an unsuccessful response from the server', () => { it('handles an unsuccessful response from the server', () => {
const error = { message: 'An error occurred!' }; const error = { message: 'An error occurred!' };
...@@ -62,6 +58,7 @@ describe('Release detail mutations', () => { ...@@ -62,6 +58,7 @@ describe('Release detail mutations', () => {
}); });
}); });
// eslint-disable-next-line jest/valid-describe
describe(types.UPDATE_RELEASE_TITLE, () => { describe(types.UPDATE_RELEASE_TITLE, () => {
it("updates the release's title", () => { it("updates the release's title", () => {
state.release = release; state.release = release;
...@@ -72,6 +69,7 @@ describe('Release detail mutations', () => { ...@@ -72,6 +69,7 @@ describe('Release detail mutations', () => {
}); });
}); });
// eslint-disable-next-line jest/valid-describe
describe(types.UPDATE_RELEASE_NOTES, () => { describe(types.UPDATE_RELEASE_NOTES, () => {
it("updates the release's notes", () => { it("updates the release's notes", () => {
state.release = release; state.release = release;
...@@ -82,6 +80,7 @@ describe('Release detail mutations', () => { ...@@ -82,6 +80,7 @@ describe('Release detail mutations', () => {
}); });
}); });
// eslint-disable-next-line jest/valid-describe
describe(types.REQUEST_UPDATE_RELEASE, () => { describe(types.REQUEST_UPDATE_RELEASE, () => {
it('set state.isUpdatingRelease to true', () => { it('set state.isUpdatingRelease to true', () => {
mutations[types.REQUEST_UPDATE_RELEASE](state); mutations[types.REQUEST_UPDATE_RELEASE](state);
...@@ -90,6 +89,7 @@ describe('Release detail mutations', () => { ...@@ -90,6 +89,7 @@ describe('Release detail mutations', () => {
}); });
}); });
// eslint-disable-next-line jest/valid-describe
describe(types.RECEIVE_UPDATE_RELEASE_SUCCESS, () => { describe(types.RECEIVE_UPDATE_RELEASE_SUCCESS, () => {
it('handles a successful response from the server', () => { it('handles a successful response from the server', () => {
mutations[types.RECEIVE_UPDATE_RELEASE_SUCCESS](state, release); mutations[types.RECEIVE_UPDATE_RELEASE_SUCCESS](state, release);
...@@ -100,6 +100,7 @@ describe('Release detail mutations', () => { ...@@ -100,6 +100,7 @@ describe('Release detail mutations', () => {
}); });
}); });
// eslint-disable-next-line jest/valid-describe
describe(types.RECEIVE_UPDATE_RELEASE_ERROR, () => { describe(types.RECEIVE_UPDATE_RELEASE_ERROR, () => {
it('handles an unsuccessful response from the server', () => { it('handles an unsuccessful response from the server', () => {
const error = { message: 'An error occurred!' }; const error = { message: 'An error occurred!' };
...@@ -111,6 +112,7 @@ describe('Release detail mutations', () => { ...@@ -111,6 +112,7 @@ describe('Release detail mutations', () => {
}); });
}); });
// eslint-disable-next-line jest/valid-describe
describe(types.ADD_EMPTY_ASSET_LINK, () => { describe(types.ADD_EMPTY_ASSET_LINK, () => {
it('adds a new, empty link object to the release', () => { it('adds a new, empty link object to the release', () => {
state.release = release; state.release = release;
...@@ -130,6 +132,7 @@ describe('Release detail mutations', () => { ...@@ -130,6 +132,7 @@ describe('Release detail mutations', () => {
}); });
}); });
// eslint-disable-next-line jest/valid-describe
describe(types.UPDATE_ASSET_LINK_URL, () => { describe(types.UPDATE_ASSET_LINK_URL, () => {
it('updates an asset link with a new URL', () => { it('updates an asset link with a new URL', () => {
state.release = release; state.release = release;
...@@ -145,6 +148,7 @@ describe('Release detail mutations', () => { ...@@ -145,6 +148,7 @@ describe('Release detail mutations', () => {
}); });
}); });
// eslint-disable-next-line jest/valid-describe
describe(types.UPDATE_ASSET_LINK_NAME, () => { describe(types.UPDATE_ASSET_LINK_NAME, () => {
it('updates an asset link with a new name', () => { it('updates an asset link with a new name', () => {
state.release = release; state.release = release;
...@@ -160,6 +164,7 @@ describe('Release detail mutations', () => { ...@@ -160,6 +164,7 @@ describe('Release detail mutations', () => {
}); });
}); });
// eslint-disable-next-line jest/valid-describe
describe(types.REMOVE_ASSET_LINK, () => { describe(types.REMOVE_ASSET_LINK, () => {
it('removes an asset link from the release', () => { it('removes an asset link from the release', () => {
state.release = release; state.release = release;
......
...@@ -47,7 +47,7 @@ describe('submitContentChanges', () => { ...@@ -47,7 +47,7 @@ describe('submitContentChanges', () => {
it('notifies error when branch could not be created', () => { it('notifies error when branch could not be created', () => {
Api.createBranch.mockRejectedValueOnce(); Api.createBranch.mockRejectedValueOnce();
expect(submitContentChanges({ username, projectId })).rejects.toThrow( return expect(submitContentChanges({ username, projectId })).rejects.toThrow(
SUBMIT_CHANGES_BRANCH_ERROR, SUBMIT_CHANGES_BRANCH_ERROR,
); );
}); });
...@@ -71,7 +71,7 @@ describe('submitContentChanges', () => { ...@@ -71,7 +71,7 @@ describe('submitContentChanges', () => {
it('notifies error when content could not be committed', () => { it('notifies error when content could not be committed', () => {
Api.commitMultiple.mockRejectedValueOnce(); Api.commitMultiple.mockRejectedValueOnce();
expect(submitContentChanges({ username, projectId })).rejects.toThrow( return expect(submitContentChanges({ username, projectId })).rejects.toThrow(
SUBMIT_CHANGES_COMMIT_ERROR, SUBMIT_CHANGES_COMMIT_ERROR,
); );
}); });
...@@ -92,7 +92,7 @@ describe('submitContentChanges', () => { ...@@ -92,7 +92,7 @@ describe('submitContentChanges', () => {
it('notifies error when merge request could not be created', () => { it('notifies error when merge request could not be created', () => {
Api.createProjectMergeRequest.mockRejectedValueOnce(); Api.createProjectMergeRequest.mockRejectedValueOnce();
expect(submitContentChanges({ username, projectId })).rejects.toThrow( return expect(submitContentChanges({ username, projectId })).rejects.toThrow(
SUBMIT_CHANGES_MERGE_REQUEST_ERROR, SUBMIT_CHANGES_MERGE_REQUEST_ERROR,
); );
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment