Commit 11a6eef6 authored by Sarah Groff Hennigh-Palermo's avatar Sarah Groff Hennigh-Palermo

Merge branch 'xanf-missing-props-on-stubs' into 'master'

Fix tests which are failing in @vue/test-utils 1.x due to stubs

See merge request gitlab-org/gitlab!40205
parents ca784b4d 80d925e8
...@@ -80,10 +80,13 @@ describe('UserToken', () => { ...@@ -80,10 +80,13 @@ describe('UserToken', () => {
describe('search', () => { describe('search', () => {
describe('when no search term is given', () => { describe('when no search term is given', () => {
it('calls `fetchData` with an empty search term', () => { it('calls `fetchData` with an empty search term', () => {
createComponent({ createComponent(
config, {
value, config,
}); value,
},
{ stubs },
);
expect(config.fetchData).toHaveBeenCalledWith(''); expect(config.fetchData).toHaveBeenCalledWith('');
}); });
...@@ -92,7 +95,7 @@ describe('UserToken', () => { ...@@ -92,7 +95,7 @@ describe('UserToken', () => {
describe('when the search term "Diddy Kong" is given', () => { describe('when the search term "Diddy Kong" is given', () => {
const data = 'Diddy Kong'; const data = 'Diddy Kong';
it('calls `fetchData` with the search term', () => { it('calls `fetchData` with the search term', () => {
createComponent({ config, value: { data } }); createComponent({ config, value: { data } }, { stubs });
expect(config.fetchData).toHaveBeenCalledWith(data); expect(config.fetchData).toHaveBeenCalledWith(data);
}); });
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlLink, GlSprintf } from '@gitlab/ui'; import { GlLink, GlSprintf } from '@gitlab/ui';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import HistoryElement from '~/packages/details/components/history_element.vue';
import component from '~/packages/details/components/package_history.vue'; import component from '~/packages/details/components/package_history.vue';
import { mavenPackage, mockPipelineInfo } from '../../mock_data'; import { mavenPackage, mockPipelineInfo } from '../../mock_data';
...@@ -16,7 +17,10 @@ describe('Package History', () => { ...@@ -16,7 +17,10 @@ describe('Package History', () => {
wrapper = shallowMount(component, { wrapper = shallowMount(component, {
propsData: { ...defaultProps, ...props }, propsData: { ...defaultProps, ...props },
stubs: { stubs: {
HistoryElement: '<div data-testid="history-element"><slot></slot></div>', HistoryElement: {
props: HistoryElement.props,
template: '<div data-testid="history-element"><slot></slot></div>',
},
GlSprintf, GlSprintf,
}, },
}); });
......
...@@ -5,16 +5,17 @@ import PipelineStatusToken from '~/pipelines/components/pipelines_list/tokens/pi ...@@ -5,16 +5,17 @@ import PipelineStatusToken from '~/pipelines/components/pipelines_list/tokens/pi
describe('Pipeline Status Token', () => { describe('Pipeline Status Token', () => {
let wrapper; let wrapper;
const findFilteredSearchToken = () => wrapper.find(GlFilteredSearchToken);
const findAllFilteredSearchSuggestions = () => wrapper.findAll(GlFilteredSearchSuggestion);
const findAllGlIcons = () => wrapper.findAll(GlIcon);
const stubs = { const stubs = {
GlFilteredSearchToken: { GlFilteredSearchToken: {
props: GlFilteredSearchToken.props,
template: `<div><slot name="suggestions"></slot></div>`, template: `<div><slot name="suggestions"></slot></div>`,
}, },
}; };
const findFilteredSearchToken = () => wrapper.find(stubs.GlFilteredSearchToken);
const findAllFilteredSearchSuggestions = () => wrapper.findAll(GlFilteredSearchSuggestion);
const findAllGlIcons = () => wrapper.findAll(GlIcon);
const defaultProps = { const defaultProps = {
config: { config: {
type: 'status', type: 'status',
...@@ -27,12 +28,12 @@ describe('Pipeline Status Token', () => { ...@@ -27,12 +28,12 @@ describe('Pipeline Status Token', () => {
}, },
}; };
const createComponent = options => { const createComponent = () => {
wrapper = shallowMount(PipelineStatusToken, { wrapper = shallowMount(PipelineStatusToken, {
propsData: { propsData: {
...defaultProps, ...defaultProps,
}, },
...options, stubs,
}); });
}; };
...@@ -50,10 +51,6 @@ describe('Pipeline Status Token', () => { ...@@ -50,10 +51,6 @@ describe('Pipeline Status Token', () => {
}); });
describe('shows statuses correctly', () => { describe('shows statuses correctly', () => {
beforeEach(() => {
createComponent({ stubs });
});
it('renders all pipeline statuses available', () => { it('renders all pipeline statuses available', () => {
expect(findAllFilteredSearchSuggestions()).toHaveLength(wrapper.vm.statuses.length); expect(findAllFilteredSearchSuggestions()).toHaveLength(wrapper.vm.statuses.length);
expect(findAllGlIcons()).toHaveLength(wrapper.vm.statuses.length); expect(findAllGlIcons()).toHaveLength(wrapper.vm.statuses.length);
......
...@@ -7,16 +7,17 @@ import { users } from '../mock_data'; ...@@ -7,16 +7,17 @@ import { users } from '../mock_data';
describe('Pipeline Trigger Author Token', () => { describe('Pipeline Trigger Author Token', () => {
let wrapper; let wrapper;
const findFilteredSearchToken = () => wrapper.find(GlFilteredSearchToken);
const findAllFilteredSearchSuggestions = () => wrapper.findAll(GlFilteredSearchSuggestion);
const findLoadingIcon = () => wrapper.find(GlLoadingIcon);
const stubs = { const stubs = {
GlFilteredSearchToken: { GlFilteredSearchToken: {
props: GlFilteredSearchToken.props,
template: `<div><slot name="suggestions"></slot></div>`, template: `<div><slot name="suggestions"></slot></div>`,
}, },
}; };
const findFilteredSearchToken = () => wrapper.find(stubs.GlFilteredSearchToken);
const findAllFilteredSearchSuggestions = () => wrapper.findAll(GlFilteredSearchSuggestion);
const findLoadingIcon = () => wrapper.find(GlLoadingIcon);
const defaultProps = { const defaultProps = {
config: { config: {
type: 'username', type: 'username',
...@@ -31,7 +32,7 @@ describe('Pipeline Trigger Author Token', () => { ...@@ -31,7 +32,7 @@ describe('Pipeline Trigger Author Token', () => {
}, },
}; };
const createComponent = (options, data) => { const createComponent = data => {
wrapper = shallowMount(PipelineTriggerAuthorToken, { wrapper = shallowMount(PipelineTriggerAuthorToken, {
propsData: { propsData: {
...defaultProps, ...defaultProps,
...@@ -41,7 +42,7 @@ describe('Pipeline Trigger Author Token', () => { ...@@ -41,7 +42,7 @@ describe('Pipeline Trigger Author Token', () => {
...data, ...data,
}; };
}, },
...options, stubs,
}); });
}; };
...@@ -69,13 +70,13 @@ describe('Pipeline Trigger Author Token', () => { ...@@ -69,13 +70,13 @@ describe('Pipeline Trigger Author Token', () => {
describe('displays loading icon correctly', () => { describe('displays loading icon correctly', () => {
it('shows loading icon', () => { it('shows loading icon', () => {
createComponent({ stubs }, { loading: true }); createComponent({ loading: true });
expect(findLoadingIcon().exists()).toBe(true); expect(findLoadingIcon().exists()).toBe(true);
}); });
it('does not show loading icon', () => { it('does not show loading icon', () => {
createComponent({ stubs }, { loading: false }); createComponent({ loading: false });
expect(findLoadingIcon().exists()).toBe(false); expect(findLoadingIcon().exists()).toBe(false);
}); });
...@@ -85,22 +86,17 @@ describe('Pipeline Trigger Author Token', () => { ...@@ -85,22 +86,17 @@ describe('Pipeline Trigger Author Token', () => {
beforeEach(() => {}); beforeEach(() => {});
it('renders all trigger authors', () => { it('renders all trigger authors', () => {
createComponent({ stubs }, { users, loading: false }); createComponent({ users, loading: false });
// should have length of all users plus the static 'Any' option // should have length of all users plus the static 'Any' option
expect(findAllFilteredSearchSuggestions()).toHaveLength(users.length + 1); expect(findAllFilteredSearchSuggestions()).toHaveLength(users.length + 1);
}); });
it('renders only the trigger author searched for', () => { it('renders only the trigger author searched for', () => {
createComponent( createComponent({
{ stubs }, users: [{ name: 'Arnold', username: 'admin', state: 'active', avatar_url: 'avatar-link' }],
{ loading: false,
users: [ });
{ name: 'Arnold', username: 'admin', state: 'active', avatar_url: 'avatar-link' },
],
loading: false,
},
);
expect(findAllFilteredSearchSuggestions()).toHaveLength(2); expect(findAllFilteredSearchSuggestions()).toHaveLength(2);
}); });
......
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