Commit 53d6a85d authored by Illya Klymov's avatar Illya Klymov Committed by Natalia Tepluhina

Fix invalid props in tests

`setProps` in `@vue/test-utils` bypasses props validation. This is
going to change in 1.x version and just feels wrong
parent 5dc5bd3b
...@@ -81,7 +81,7 @@ describe('RequirementsTabs', () => { ...@@ -81,7 +81,7 @@ describe('RequirementsTabs', () => {
it('does not render "New requirement" button when current tab is not "Open" tab', () => { it('does not render "New requirement" button when current tab is not "Open" tab', () => {
wrapper.setProps({ wrapper.setProps({
filterBy: FilterState.closed, filterBy: FilterState.archived,
}); });
return wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
......
import { config as vueConfig } from 'vue';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import IssueTimeEstimate from '~/boards/components/issue_time_estimate.vue'; import IssueTimeEstimate from '~/boards/components/issue_time_estimate.vue';
...@@ -28,15 +29,20 @@ describe('Issue Time Estimate component', () => { ...@@ -28,15 +29,20 @@ describe('Issue Time Estimate component', () => {
expect(wrapper.find('.js-issue-time-estimate').text()).toContain('2 weeks 3 days 1 minute'); expect(wrapper.find('.js-issue-time-estimate').text()).toContain('2 weeks 3 days 1 minute');
}); });
it('prevents tooltip xss', (done) => { it('prevents tooltip xss', async () => {
const alertSpy = jest.spyOn(window, 'alert'); const alertSpy = jest.spyOn(window, 'alert');
wrapper.setProps({ estimate: 'Foo <script>alert("XSS")</script>' });
wrapper.vm.$nextTick(() => { try {
// This will raise props validating warning by Vue, silencing it
vueConfig.silent = true;
await wrapper.setProps({ estimate: 'Foo <script>alert("XSS")</script>' });
} finally {
vueConfig.silent = false;
}
expect(alertSpy).not.toHaveBeenCalled(); expect(alertSpy).not.toHaveBeenCalled();
expect(wrapper.find('time').text().trim()).toEqual('0m'); expect(wrapper.find('time').text().trim()).toEqual('0m');
expect(wrapper.find('.js-issue-time-estimate').text()).toContain('0m'); expect(wrapper.find('.js-issue-time-estimate').text()).toContain('0m');
done();
});
}); });
}); });
......
...@@ -8,9 +8,9 @@ import DropdownSearchInput from '~/vue_shared/components/dropdown/dropdown_searc ...@@ -8,9 +8,9 @@ import DropdownSearchInput from '~/vue_shared/components/dropdown/dropdown_searc
describe('ClusterFormDropdown', () => { describe('ClusterFormDropdown', () => {
let wrapper; let wrapper;
const firstItem = { name: 'item 1', value: 1 }; const firstItem = { name: 'item 1', value: '1' };
const secondItem = { name: 'item 2', value: 2 }; const secondItem = { name: 'item 2', value: '2' };
const items = [firstItem, secondItem, { name: 'item 3', value: 3 }]; const items = [firstItem, secondItem, { name: 'item 3', value: '3' }];
beforeEach(() => { beforeEach(() => {
wrapper = shallowMount(ClusterFormDropdown); wrapper = shallowMount(ClusterFormDropdown);
...@@ -55,7 +55,7 @@ describe('ClusterFormDropdown', () => { ...@@ -55,7 +55,7 @@ describe('ClusterFormDropdown', () => {
}); });
describe('when multiple items are selected', () => { describe('when multiple items are selected', () => {
const value = [1]; const value = ['1'];
beforeEach(() => { beforeEach(() => {
wrapper.setProps({ items, multiple: true, value }); wrapper.setProps({ items, multiple: true, value });
...@@ -104,7 +104,7 @@ describe('ClusterFormDropdown', () => { ...@@ -104,7 +104,7 @@ describe('ClusterFormDropdown', () => {
it('displays selected item custom label', () => { it('displays selected item custom label', () => {
const labelProperty = 'customLabel'; const labelProperty = 'customLabel';
const label = 'Name'; const label = 'Name';
const currentValue = 1; const currentValue = '1';
const customLabelItems = [{ [labelProperty]: label, value: currentValue }]; const customLabelItems = [{ [labelProperty]: label, value: currentValue }];
wrapper.setProps({ labelProperty, items: customLabelItems, value: currentValue }); wrapper.setProps({ labelProperty, items: customLabelItems, value: currentValue });
...@@ -116,14 +116,11 @@ describe('ClusterFormDropdown', () => { ...@@ -116,14 +116,11 @@ describe('ClusterFormDropdown', () => {
}); });
describe('when loading', () => { describe('when loading', () => {
it('dropdown button isLoading', () => { it('dropdown button isLoading', async () => {
wrapper.setProps({ loading: true }); await wrapper.setProps({ loading: true });
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.find(DropdownButton).props('isLoading')).toBe(true); expect(wrapper.find(DropdownButton).props('isLoading')).toBe(true);
}); });
}); });
});
describe('when loading and loadingText is provided', () => { describe('when loading and loadingText is provided', () => {
it('uses loading text as toggle button text', () => { it('uses loading text as toggle button text', () => {
......
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