Commit 1885b4f0 authored by peterhegman's avatar peterhegman Committed by Miguel Rincon

Update VTU to v1.2.0

Also update `extendedWrapper` to return `ErrorWrapper` if no elements
are found
parent 0b227705
...@@ -10,7 +10,7 @@ export default { ...@@ -10,7 +10,7 @@ export default {
}, },
props: { props: {
estimate: { estimate: {
type: Number, type: [Number, String],
required: true, required: true,
}, },
}, },
......
import * as testingLibrary from '@testing-library/dom'; import * as testingLibrary from '@testing-library/dom';
import { createWrapper, WrapperArray, mount, shallowMount } from '@vue/test-utils'; import { createWrapper, WrapperArray, ErrorWrapper, mount, shallowMount } from '@vue/test-utils';
import { isArray, upperFirst } from 'lodash'; import { isArray, upperFirst } from 'lodash';
const vNodeContainsText = (vnode, text) => const vNodeContainsText = (vnode, text) =>
...@@ -81,14 +81,9 @@ export const extendedWrapper = (wrapper) => { ...@@ -81,14 +81,9 @@ export const extendedWrapper = (wrapper) => {
options, options,
); );
// Return VTU `ErrorWrapper` if element is not found // Element not found, return an `ErrorWrapper`
// https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/src/error-wrapper.js
// VTU does not expose `ErrorWrapper` so, as of now, this is the best way to
// create an `ErrorWrapper`
if (!elements.length) { if (!elements.length) {
const emptyElement = document.createElement('div'); return new ErrorWrapper(query);
return createWrapper(emptyElement).find('testing-library-element-not-found');
} }
return createWrapper(elements[0], this.options || {}); return createWrapper(elements[0], this.options || {});
......
...@@ -4,6 +4,7 @@ import { ...@@ -4,6 +4,7 @@ import {
shallowMount, shallowMount,
Wrapper as VTUWrapper, Wrapper as VTUWrapper,
WrapperArray as VTUWrapperArray, WrapperArray as VTUWrapperArray,
ErrorWrapper as VTUErrorWrapper,
} from '@vue/test-utils'; } from '@vue/test-utils';
import { import {
extendedWrapper, extendedWrapper,
...@@ -195,7 +196,7 @@ describe('Vue test utils helpers', () => { ...@@ -195,7 +196,7 @@ describe('Vue test utils helpers', () => {
}); });
it('returns a VTU error wrapper', () => { it('returns a VTU error wrapper', () => {
expect(wrapper[findMethod](text, options).exists()).toBe(false); expect(wrapper[findMethod](text, options)).toBeInstanceOf(VTUErrorWrapper);
}); });
}); });
}); });
......
...@@ -656,7 +656,7 @@ describe('RepoEditor', () => { ...@@ -656,7 +656,7 @@ describe('RepoEditor', () => {
}); });
it("does not add file to state or set markdown image syntax if the file isn't markdown", async () => { it("does not add file to state or set markdown image syntax if the file isn't markdown", async () => {
wrapper.setProps({ await wrapper.setProps({
file: setFileName('myfile.txt'), file: setFileName('myfile.txt'),
}); });
pasteImage(); pasteImage();
......
...@@ -20,7 +20,7 @@ const createUnallowedNote = () => ...@@ -20,7 +20,7 @@ const createUnallowedNote = () =>
describe('DiscussionActions', () => { describe('DiscussionActions', () => {
let wrapper; let wrapper;
const createComponentFactory = (shallow = true) => (props) => { const createComponentFactory = (shallow = true) => (props, options) => {
const store = createStore(); const store = createStore();
const mountFn = shallow ? shallowMount : mount; const mountFn = shallow ? shallowMount : mount;
...@@ -34,6 +34,7 @@ describe('DiscussionActions', () => { ...@@ -34,6 +34,7 @@ describe('DiscussionActions', () => {
shouldShowJumpToNextDiscussion: true, shouldShowJumpToNextDiscussion: true,
...props, ...props,
}, },
...options,
}); });
}; };
...@@ -90,17 +91,17 @@ describe('DiscussionActions', () => { ...@@ -90,17 +91,17 @@ describe('DiscussionActions', () => {
describe('events handling', () => { describe('events handling', () => {
const createComponent = createComponentFactory(false); const createComponent = createComponentFactory(false);
beforeEach(() => {
createComponent();
});
it('emits showReplyForm event when clicking on reply placeholder', () => { it('emits showReplyForm event when clicking on reply placeholder', () => {
createComponent({}, { attachTo: document.body });
jest.spyOn(wrapper.vm, '$emit'); jest.spyOn(wrapper.vm, '$emit');
wrapper.find(ReplyPlaceholder).find('textarea').trigger('focus'); wrapper.find(ReplyPlaceholder).find('textarea').trigger('focus');
expect(wrapper.vm.$emit).toHaveBeenCalledWith('showReplyForm'); expect(wrapper.vm.$emit).toHaveBeenCalledWith('showReplyForm');
}); });
it('emits resolve event when clicking on resolve button', () => { it('emits resolve event when clicking on resolve button', () => {
createComponent();
jest.spyOn(wrapper.vm, '$emit'); jest.spyOn(wrapper.vm, '$emit');
wrapper.find(ResolveDiscussionButton).find('button').trigger('click'); wrapper.find(ResolveDiscussionButton).find('button').trigger('click');
expect(wrapper.vm.$emit).toHaveBeenCalledWith('resolve'); expect(wrapper.vm.$emit).toHaveBeenCalledWith('resolve');
......
...@@ -6,31 +6,34 @@ const placeholderText = 'Test Button Text'; ...@@ -6,31 +6,34 @@ const placeholderText = 'Test Button Text';
describe('ReplyPlaceholder', () => { describe('ReplyPlaceholder', () => {
let wrapper; let wrapper;
const findTextarea = () => wrapper.find({ ref: 'textarea' }); const createComponent = ({ options = {} } = {}) => {
beforeEach(() => {
wrapper = shallowMount(ReplyPlaceholder, { wrapper = shallowMount(ReplyPlaceholder, {
propsData: { propsData: {
placeholderText, placeholderText,
}, },
...options,
}); });
}); };
const findTextarea = () => wrapper.find({ ref: 'textarea' });
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
it('emits focus event on button click', () => { it('emits focus event on button click', async () => {
findTextarea().trigger('focus'); createComponent({ options: { attachTo: document.body } });
await findTextarea().trigger('focus');
return wrapper.vm.$nextTick().then(() => { expect(wrapper.emitted()).toEqual({
expect(wrapper.emitted()).toEqual({ focus: [[]],
focus: [[]],
});
}); });
}); });
it('should render reply button', () => { it('should render reply button', () => {
createComponent();
expect(findTextarea().attributes('placeholder')).toEqual(placeholderText); expect(findTextarea().attributes('placeholder')).toEqual(placeholderText);
}); });
}); });
...@@ -66,7 +66,7 @@ exports[`Code Coverage when fetching data is successful matches the snapshot 1`] ...@@ -66,7 +66,7 @@ exports[`Code Coverage when fetching data is successful matches the snapshot 1`]
<gl-area-chart-stub <gl-area-chart-stub
annotations="" annotations=""
data="[object Object]" data="[object Object]"
formattooltiptext="function () { [native code] }" formattooltiptext="[Function]"
height="200" height="200"
includelegendavgmax="true" includelegendavgmax="true"
legendaveragetext="Avg" legendaveragetext="Avg"
......
...@@ -1816,10 +1816,10 @@ ...@@ -1816,10 +1816,10 @@
source-map "~0.6.1" source-map "~0.6.1"
vue-template-es2015-compiler "^1.9.0" vue-template-es2015-compiler "^1.9.0"
"@vue/test-utils@1.1.2": "@vue/test-utils@1.2.0":
version "1.1.2" version "1.2.0"
resolved "https://registry.yarnpkg.com/@vue/test-utils/-/test-utils-1.1.2.tgz#fdb487448dceefeaf3d01d465f7c836a3d666dbc" resolved "https://registry.yarnpkg.com/@vue/test-utils/-/test-utils-1.2.0.tgz#3bc8c17ed549157275f0aec6b95da40887f7297f"
integrity sha512-utbIL7zn9c+SjhybPwh48lpWCiluFCbP1yyRNAy1fQsw/6hiNFioaWy05FoVAFIZXC5WwBf+5r4ypfM1j/nI4A== integrity sha512-poBTLqeJYNq1TXVhtVfnY8vELUVOFdJY8KZZoUuaAkIqPTWsxonU1M8nMWpZT+xEMrM+49+YcuEqtMHVD9Q9gw==
dependencies: dependencies:
dom-event-types "^1.0.0" dom-event-types "^1.0.0"
lodash "^4.17.15" lodash "^4.17.15"
......
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