Commit 676c6d64 authored by Scott Hampton's avatar Scott Hampton

Refactor test coverage table spec

Refactor to use `nextTick` from `vue`. Moved
repeated code to the `clickSelectAllProjects`
function.
parent 461b9f5e
import { GlTable } from '@gitlab/ui'; import { GlTable } from '@gitlab/ui';
import { mount, shallowMount, createLocalVue } from '@vue/test-utils'; import { mount, shallowMount, createLocalVue } from '@vue/test-utils';
import { nextTick } from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import SelectProjectsDropdown from 'ee/analytics/repository_analytics/components/select_projects_dropdown.vue'; import SelectProjectsDropdown from 'ee/analytics/repository_analytics/components/select_projects_dropdown.vue';
import TestCoverageTable from 'ee/analytics/repository_analytics/components/test_coverage_table.vue'; import TestCoverageTable from 'ee/analytics/repository_analytics/components/test_coverage_table.vue';
...@@ -34,7 +35,9 @@ describe('Test coverage table component', () => { ...@@ -34,7 +35,9 @@ describe('Test coverage table component', () => {
const clickSelectAllProjects = async () => { const clickSelectAllProjects = async () => {
findProjectsDropdown().vm.$emit('select-all-projects'); findProjectsDropdown().vm.$emit('select-all-projects');
await wrapper.vm.$nextTick(); await nextTick();
jest.runOnlyPendingTimers();
await nextTick();
}; };
const createComponent = ({ glFeatures = {}, mockData = {}, mountFn = shallowMount } = {}) => { const createComponent = ({ glFeatures = {}, mockData = {}, mountFn = shallowMount } = {}) => {
...@@ -98,8 +101,6 @@ describe('Test coverage table component', () => { ...@@ -98,8 +101,6 @@ describe('Test coverage table component', () => {
createComponent({ mountFn: mount }); createComponent({ mountFn: mount });
await clickSelectAllProjects(); await clickSelectAllProjects();
jest.runOnlyPendingTimers();
await wrapper.vm.$nextTick();
expect(getProjectsTestCoverageSpy).toHaveBeenCalled(); expect(getProjectsTestCoverageSpy).toHaveBeenCalled();
...@@ -146,8 +147,6 @@ describe('Test coverage table component', () => { ...@@ -146,8 +147,6 @@ describe('Test coverage table component', () => {
createComponent({ mountFn: mount }); createComponent({ mountFn: mount });
await clickSelectAllProjects(); await clickSelectAllProjects();
jest.runOnlyPendingTimers();
await wrapper.vm.$nextTick();
expect(findTable().exists()).toBe(true); expect(findTable().exists()).toBe(true);
expect(findTableRows().at(0).text()).toContain('should be first'); expect(findTableRows().at(0).text()).toContain('should be first');
...@@ -164,8 +163,6 @@ describe('Test coverage table component', () => { ...@@ -164,8 +163,6 @@ describe('Test coverage table component', () => {
createComponent({ mountFn: mount }); createComponent({ mountFn: mount });
await clickSelectAllProjects(); await clickSelectAllProjects();
jest.runOnlyPendingTimers();
await wrapper.vm.$nextTick();
expect(findTable().exists()).toBe(true); expect(findTable().exists()).toBe(true);
expect(findProjectNameById(id).attributes('href')).toBe(expectedPath); expect(findProjectNameById(id).attributes('href')).toBe(expectedPath);
...@@ -182,8 +179,6 @@ describe('Test coverage table component', () => { ...@@ -182,8 +179,6 @@ describe('Test coverage table component', () => {
}); });
await clickSelectAllProjects(); await clickSelectAllProjects();
jest.runOnlyPendingTimers();
await wrapper.vm.$nextTick();
findProjectNameById(id).trigger('click'); findProjectNameById(id).trigger('click');
...@@ -203,8 +198,6 @@ describe('Test coverage table component', () => { ...@@ -203,8 +198,6 @@ describe('Test coverage table component', () => {
}); });
await clickSelectAllProjects(); await clickSelectAllProjects();
jest.runOnlyPendingTimers();
await wrapper.vm.$nextTick();
findProjectNameById(id).trigger('click'); findProjectNameById(id).trigger('click');
......
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