diff options
Diffstat (limited to 'spec/frontend')
14 files changed, 84 insertions, 78 deletions
diff --git a/spec/frontend/.eslintrc.yml b/spec/frontend/.eslintrc.yml index 054dc27cda6..ff18f0e4a2d 100644 --- a/spec/frontend/.eslintrc.yml +++ b/spec/frontend/.eslintrc.yml @@ -12,3 +12,8 @@ globals: loadFixtures: false preloadFixtures: false setFixtures: false +rules: + jest/no-identical-title: error + jest/no-focused-tests: error + jest/valid-describe: error + jest/no-jasmine-globals: error diff --git a/spec/frontend/error_tracking/components/error_tracking_list_spec.js b/spec/frontend/error_tracking/components/error_tracking_list_spec.js index 503af3920a8..67e5dc399ac 100644 --- a/spec/frontend/error_tracking/components/error_tracking_list_spec.js +++ b/spec/frontend/error_tracking/components/error_tracking_list_spec.js @@ -31,7 +31,7 @@ describe('ErrorTrackingList', () => { actions = { getErrorList: () => {}, startPolling: () => {}, - restartPolling: jasmine.createSpy('restartPolling'), + restartPolling: jest.fn().mockName('restartPolling'), }; const state = { diff --git a/spec/frontend/filtered_search/services/recent_searches_service_error_spec.js b/spec/frontend/filtered_search/services/recent_searches_service_error_spec.js index ea7c146fa4f..0e62bc94517 100644 --- a/spec/frontend/filtered_search/services/recent_searches_service_error_spec.js +++ b/spec/frontend/filtered_search/services/recent_searches_service_error_spec.js @@ -8,7 +8,7 @@ describe('RecentSearchesServiceError', () => { }); it('instantiates an instance of RecentSearchesServiceError and not an Error', () => { - expect(recentSearchesServiceError).toEqual(jasmine.any(RecentSearchesServiceError)); + expect(recentSearchesServiceError).toEqual(expect.any(RecentSearchesServiceError)); expect(recentSearchesServiceError.name).toBe('RecentSearchesServiceError'); }); diff --git a/spec/frontend/ide/lib/common/disposable_spec.js b/spec/frontend/ide/lib/common/disposable_spec.js index af12ca15369..8596642eb7a 100644 --- a/spec/frontend/ide/lib/common/disposable_spec.js +++ b/spec/frontend/ide/lib/common/disposable_spec.js @@ -8,7 +8,7 @@ describe('Multi-file editor library disposable class', () => { instance = new Disposable(); disposableClass = { - dispose: jasmine.createSpy('dispose'), + dispose: jest.fn().mockName('dispose'), }; }); diff --git a/spec/frontend/ide/lib/diff/diff_spec.js b/spec/frontend/ide/lib/diff/diff_spec.js index 57f3ac3d365..d9b088e2c12 100644 --- a/spec/frontend/ide/lib/diff/diff_spec.js +++ b/spec/frontend/ide/lib/diff/diff_spec.js @@ -9,60 +9,57 @@ describe('Multi-file editor library diff calculator', () => { }); describe('modified', () => { - it('', () => { - const diff = computeDiff('123', '1234')[0]; - - expect(diff.added).toBeTruthy(); - expect(diff.modified).toBeTruthy(); - expect(diff.removed).toBeUndefined(); - }); - - it('', () => { - const diff = computeDiff('123\n123\n123', '123\n1234\n123')[0]; - - expect(diff.added).toBeTruthy(); - expect(diff.modified).toBeTruthy(); - expect(diff.removed).toBeUndefined(); - expect(diff.lineNumber).toBe(2); - }); + it.each` + originalContent | newContent | lineNumber + ${'123'} | ${'1234'} | ${1} + ${'123\n123\n123'} | ${'123\n1234\n123'} | ${2} + `( + 'marks line $lineNumber as added and modified but not removed', + ({ originalContent, newContent, lineNumber }) => { + const diff = computeDiff(originalContent, newContent)[0]; + + expect(diff.added).toBeTruthy(); + expect(diff.modified).toBeTruthy(); + expect(diff.removed).toBeUndefined(); + expect(diff.lineNumber).toBe(lineNumber); + }, + ); }); describe('added', () => { - it('', () => { - const diff = computeDiff('123', '123\n123')[0]; - - expect(diff.added).toBeTruthy(); - expect(diff.modified).toBeUndefined(); - expect(diff.removed).toBeUndefined(); - }); - - it('', () => { - const diff = computeDiff('123\n123\n123', '123\n123\n1234\n123')[0]; - - expect(diff.added).toBeTruthy(); - expect(diff.modified).toBeUndefined(); - expect(diff.removed).toBeUndefined(); - expect(diff.lineNumber).toBe(3); - }); + it.each` + originalContent | newContent | lineNumber + ${'123'} | ${'123\n123'} | ${1} + ${'123\n123\n123'} | ${'123\n123\n1234\n123'} | ${3} + `( + 'marks line $lineNumber as added but not modified and not removed', + ({ originalContent, newContent, lineNumber }) => { + const diff = computeDiff(originalContent, newContent)[0]; + + expect(diff.added).toBeTruthy(); + expect(diff.modified).toBeUndefined(); + expect(diff.removed).toBeUndefined(); + expect(diff.lineNumber).toBe(lineNumber); + }, + ); }); describe('removed', () => { - it('', () => { - const diff = computeDiff('123', '')[0]; - - expect(diff.added).toBeUndefined(); - expect(diff.modified).toBeUndefined(); - expect(diff.removed).toBeTruthy(); - }); - - it('', () => { - const diff = computeDiff('123\n123\n123', '123\n123')[0]; - - expect(diff.added).toBeUndefined(); - expect(diff.modified).toBeTruthy(); - expect(diff.removed).toBeTruthy(); - expect(diff.lineNumber).toBe(2); - }); + it.each` + originalContent | newContent | lineNumber | modified + ${'123'} | ${''} | ${1} | ${undefined} + ${'123\n123\n123'} | ${'123\n123'} | ${2} | ${true} + `( + 'marks line $lineNumber as removed', + ({ originalContent, newContent, lineNumber, modified }) => { + const diff = computeDiff(originalContent, newContent)[0]; + + expect(diff.added).toBeUndefined(); + expect(diff.modified).toBe(modified); + expect(diff.removed).toBeTruthy(); + expect(diff.lineNumber).toBe(lineNumber); + }, + ); }); it('includes line number of change', () => { diff --git a/spec/frontend/ide/lib/editor_options_spec.js b/spec/frontend/ide/lib/editor_options_spec.js index d149a883166..b07a583b7c8 100644 --- a/spec/frontend/ide/lib/editor_options_spec.js +++ b/spec/frontend/ide/lib/editor_options_spec.js @@ -2,7 +2,7 @@ import editorOptions from '~/ide/lib/editor_options'; describe('Multi-file editor library editor options', () => { it('returns an array', () => { - expect(editorOptions).toEqual(jasmine.any(Array)); + expect(editorOptions).toEqual(expect.any(Array)); }); it('contains readOnly option', () => { diff --git a/spec/frontend/ide/stores/modules/file_templates/mutations_spec.js b/spec/frontend/ide/stores/modules/file_templates/mutations_spec.js index 8e0e3ae99a1..8e8b7f06ca2 100644 --- a/spec/frontend/ide/stores/modules/file_templates/mutations_spec.js +++ b/spec/frontend/ide/stores/modules/file_templates/mutations_spec.js @@ -9,7 +9,7 @@ describe('IDE file templates mutations', () => { state = createState(); }); - describe(types.REQUEST_TEMPLATE_TYPES, () => { + describe(`${types.REQUEST_TEMPLATE_TYPES}`, () => { it('sets isLoading', () => { mutations[types.REQUEST_TEMPLATE_TYPES](state); @@ -17,7 +17,7 @@ describe('IDE file templates mutations', () => { }); }); - describe(types.RECEIVE_TEMPLATE_TYPES_ERROR, () => { + describe(`${types.RECEIVE_TEMPLATE_TYPES_ERROR}`, () => { it('sets isLoading', () => { state.isLoading = true; @@ -27,7 +27,7 @@ describe('IDE file templates mutations', () => { }); }); - describe(types.RECEIVE_TEMPLATE_TYPES_SUCCESS, () => { + describe(`${types.RECEIVE_TEMPLATE_TYPES_SUCCESS}`, () => { it('sets isLoading to false', () => { state.isLoading = true; @@ -43,7 +43,7 @@ describe('IDE file templates mutations', () => { }); }); - describe(types.SET_SELECTED_TEMPLATE_TYPE, () => { + describe(`${types.SET_SELECTED_TEMPLATE_TYPE}`, () => { it('sets selectedTemplateType', () => { mutations[types.SET_SELECTED_TEMPLATE_TYPE](state, 'type'); @@ -59,7 +59,7 @@ describe('IDE file templates mutations', () => { }); }); - describe(types.SET_UPDATE_SUCCESS, () => { + describe(`${types.SET_UPDATE_SUCCESS}`, () => { it('sets updateSuccess', () => { mutations[types.SET_UPDATE_SUCCESS](state, true); diff --git a/spec/frontend/import_projects/store/mutations_spec.js b/spec/frontend/import_projects/store/mutations_spec.js index 8db8e9819ba..505545f7aa5 100644 --- a/spec/frontend/import_projects/store/mutations_spec.js +++ b/spec/frontend/import_projects/store/mutations_spec.js @@ -2,7 +2,7 @@ import * as types from '~/import_projects/store/mutation_types'; import mutations from '~/import_projects/store/mutations'; describe('import_projects store mutations', () => { - describe(types.RECEIVE_IMPORT_SUCCESS, () => { + describe(`${types.RECEIVE_IMPORT_SUCCESS}`, () => { it('removes repoId from reposBeingImported and providerRepos, adds to importedProjects', () => { const repoId = 1; const state = { @@ -20,7 +20,7 @@ describe('import_projects store mutations', () => { }); }); - describe(types.RECEIVE_JOBS_SUCCESS, () => { + describe(`${types.RECEIVE_JOBS_SUCCESS}`, () => { it('updates importStatus of existing importedProjects', () => { const repoId = 1; const state = { importedProjects: [{ id: repoId, importStatus: 'started' }] }; diff --git a/spec/frontend/pages/admin/abuse_reports/abuse_reports_spec.js b/spec/frontend/pages/admin/abuse_reports/abuse_reports_spec.js index 1e0bc708c31..7e9aec84016 100644 --- a/spec/frontend/pages/admin/abuse_reports/abuse_reports_spec.js +++ b/spec/frontend/pages/admin/abuse_reports/abuse_reports_spec.js @@ -25,14 +25,14 @@ describe('Abuse Reports', () => { it('should truncate long messages', () => { const $longMessage = findMessage('LONG MESSAGE'); - expect($longMessage.data('originalMessage')).toEqual(jasmine.anything()); + expect($longMessage.data('originalMessage')).toEqual(expect.anything()); assertMaxLength($longMessage); }); it('should not truncate short messages', () => { const $shortMessage = findMessage('SHORT MESSAGE'); - expect($shortMessage.data('originalMessage')).not.toEqual(jasmine.anything()); + expect($shortMessage.data('originalMessage')).not.toEqual(expect.anything()); }); it('should allow clicking a truncated message to expand and collapse the full message', () => { diff --git a/spec/frontend/pages/profiles/show/emoji_menu_spec.js b/spec/frontend/pages/profiles/show/emoji_menu_spec.js index efc338b36eb..6ac1e83829f 100644 --- a/spec/frontend/pages/profiles/show/emoji_menu_spec.js +++ b/spec/frontend/pages/profiles/show/emoji_menu_spec.js @@ -13,7 +13,7 @@ describe('EmojiMenu', () => { let dummyEmojiList; beforeEach(() => { - dummySelectEmojiCallback = jasmine.createSpy('dummySelectEmojiCallback'); + dummySelectEmojiCallback = jest.fn().mockName('dummySelectEmojiCallback'); dummyEmojiList = { glEmojiTag() { return dummyEmojiTag; @@ -75,19 +75,19 @@ describe('EmojiMenu', () => { expect(emojiMenu.registerEventListener).toHaveBeenCalledWith( 'one', - jasmine.anything(), + expect.anything(), 'mouseenter focus', dummyToggleButtonSelector, 'mouseenter focus', - jasmine.anything(), + expect.anything(), ); expect(emojiMenu.registerEventListener).toHaveBeenCalledWith( 'on', - jasmine.anything(), + expect.anything(), 'click', dummyToggleButtonSelector, - jasmine.anything(), + expect.anything(), ); }); @@ -96,10 +96,10 @@ describe('EmojiMenu', () => { expect(emojiMenu.registerEventListener).toHaveBeenCalledWith( 'on', - jasmine.anything(), + expect.anything(), 'click', `.js-awards-block .js-emoji-btn, .${dummyMenuClass} .js-emoji-btn`, - jasmine.anything(), + expect.anything(), ); }); }); diff --git a/spec/frontend/serverless/components/functions_spec.js b/spec/frontend/serverless/components/functions_spec.js index 5533de1a70a..7af33ceaadc 100644 --- a/spec/frontend/serverless/components/functions_spec.js +++ b/spec/frontend/serverless/components/functions_spec.js @@ -4,14 +4,21 @@ import axios from '~/lib/utils/axios_utils'; import functionsComponent from '~/serverless/components/functions.vue'; import { createLocalVue, shallowMount } from '@vue/test-utils'; import { createStore } from '~/serverless/store'; +import { TEST_HOST } from 'helpers/test_constants'; import { mockServerlessFunctions } from '../mock_data'; describe('functionsComponent', () => { + const statusPath = `${TEST_HOST}/statusPath`; + let component; let store; let localVue; + let axiosMock; beforeEach(() => { + axiosMock = new AxiosMockAdapter(axios); + axiosMock.onGet(statusPath).reply(200); + localVue = createLocalVue(); localVue.use(Vuex); @@ -20,6 +27,7 @@ describe('functionsComponent', () => { afterEach(() => { component.vm.$destroy(); + axiosMock.restore(); }); it('should render empty state when Knative is not installed', () => { @@ -80,11 +88,7 @@ describe('functionsComponent', () => { ); }); - fit('should render the functions list', () => { - const statusPath = 'statusPath'; - const axiosMock = new AxiosMockAdapter(axios); - axiosMock.onGet(statusPath).reply(200); - + it('should render the functions list', () => { component = shallowMount(functionsComponent, { localVue, store, diff --git a/spec/frontend/vue_shared/components/markdown/suggestion_diff_row_spec.js b/spec/frontend/vue_shared/components/markdown/suggestion_diff_row_spec.js index 866d6eb05c6..c8deac1c086 100644 --- a/spec/frontend/vue_shared/components/markdown/suggestion_diff_row_spec.js +++ b/spec/frontend/vue_shared/components/markdown/suggestion_diff_row_spec.js @@ -23,7 +23,7 @@ const newLine = { type: 'new', }; -describe(SuggestionDiffRow.name, () => { +describe('SuggestionDiffRow', () => { let wrapper; const factory = (options = {}) => { diff --git a/spec/frontend/vue_shared/components/notes/timeline_entry_item_spec.js b/spec/frontend/vue_shared/components/notes/timeline_entry_item_spec.js index c15635f2105..be6c58f0683 100644 --- a/spec/frontend/vue_shared/components/notes/timeline_entry_item_spec.js +++ b/spec/frontend/vue_shared/components/notes/timeline_entry_item_spec.js @@ -1,7 +1,7 @@ import { shallowMount, createLocalVue } from '@vue/test-utils'; import TimelineEntryItem from '~/vue_shared/components/notes/timeline_entry_item.vue'; -describe(TimelineEntryItem.name, () => { +describe(`TimelineEntryItem`, () => { let wrapper; const factory = (options = {}) => { diff --git a/spec/frontend/vuex_shared/modules/modal/mutations_spec.js b/spec/frontend/vuex_shared/modules/modal/mutations_spec.js index d07f8ba1e65..eaaf196d1ec 100644 --- a/spec/frontend/vuex_shared/modules/modal/mutations_spec.js +++ b/spec/frontend/vuex_shared/modules/modal/mutations_spec.js @@ -2,7 +2,7 @@ import mutations from '~/vuex_shared/modules/modal/mutations'; import * as types from '~/vuex_shared/modules/modal/mutation_types'; describe('Vuex ModalModule mutations', () => { - describe(types.SHOW, () => { + describe(`${types.SHOW}`, () => { it('sets isVisible to true', () => { const state = { isVisible: false, @@ -16,7 +16,7 @@ describe('Vuex ModalModule mutations', () => { }); }); - describe(types.HIDE, () => { + describe(`${types.HIDE}`, () => { it('sets isVisible to false', () => { const state = { isVisible: true, @@ -30,7 +30,7 @@ describe('Vuex ModalModule mutations', () => { }); }); - describe(types.OPEN, () => { + describe(`${types.OPEN}`, () => { it('sets data and sets isVisible to true', () => { const data = { id: 7 }; const state = { |