From 8ec7f92ee12fd389f524b2bc3d05449caaae5e7b Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Mon, 24 Dec 2018 20:51:26 +0000 Subject: [PATCH 1/5] fix: remove click from setChecked --- packages/test-utils/src/wrapper.js | 38 +++++++++------------------ test/specs/wrapper/setChecked.spec.js | 36 +++++++------------------ 2 files changed, 22 insertions(+), 52 deletions(-) diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index 4d13e0c25..b49c01bcd 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -40,7 +40,7 @@ export default class Wrapper implements BaseWrapper { // $FlowIgnore : issue with defineProperty Object.defineProperty(this, 'rootNode', { get: () => vnode || element, - set: () => throwError('wrapper.vnode is read-only') + set: () => throwError('wrapper.rootNode is read-only') }) // $FlowIgnore Object.defineProperty(this, 'vnode', { @@ -488,23 +488,14 @@ export default class Wrapper implements BaseWrapper { // $FlowIgnore const type = this.attributes().type - if (tagName === 'SELECT') { - throwError( - `wrapper.setChecked() cannot be called on a ` + - ` element.' - shouldThrowErrorOnElement('#radioFoo', message, false) - }) - - it('throws error if element is select', () => { - const message = - 'wrapper.setChecked() cannot be called on a element. Use ` + - `wrapper.setChecked() instead` - ) - } else if (tagName === 'INPUT' && type === 'radio') { - throwError( - `wrapper.setSelected() cannot be called on a element. Use wrapper.setChecked() ` + - `instead` - ) - } else if (tagName === 'INPUT' || tagName === 'TEXTAREA') { - throwError( - `wrapper.setSelected() cannot be called on "text" ` + - `inputs. Use wrapper.setValue() instead` - ) - } else { - throwError(`wrapper.setSelected() cannot be called on this element`) + + // $FlowIgnore + createWrapper(parentElement, this.options).trigger('change') + return } + + throwError(`wrapper.setSelected() cannot be called on this element`) } /** diff --git a/test/specs/wrapper/setSelected.spec.js b/test/specs/wrapper/setSelected.spec.js index 5b6375d5f..e33c481ab 100644 --- a/test/specs/wrapper/setSelected.spec.js +++ b/test/specs/wrapper/setSelected.spec.js @@ -1,7 +1,7 @@ import ComponentWithInput from '~resources/components/component-with-input.vue' import { describeWithShallowAndMount } from '~resources/utils' -describeWithShallowAndMount('setSelected', mountingMethod => { +describeWithShallowAndMount.only('setSelected', mountingMethod => { it('sets element selected true', () => { const wrapper = mountingMethod(ComponentWithInput) const options = wrapper.find('select').findAll('option') @@ -33,37 +33,15 @@ describeWithShallowAndMount('setSelected', mountingMethod => { expect(wrapper.text()).to.contain('selectA') }) - it('throws error if element is radio', () => { - const message = - 'wrapper.setSelected() cannot be called on a element. Use wrapper.setChecked() instead' - shouldThrowErrorOnElement('input[type="radio"]', message) - }) - - it('throws error if element is radio', () => { - const message = - 'wrapper.setSelected() cannot be called on a element. Use wrapper.setChecked() instead' - shouldThrowErrorOnElement('input[type="checkbox"]', message) - }) - - it('throws error if element is text like', () => { - const message = - 'wrapper.setSelected() cannot be called on "text" inputs. Use wrapper.setValue() instead' - shouldThrowErrorOnElement('input[type="text"]', message) - shouldThrowErrorOnElement('textarea', message) - }) - it('throws error if element is not valid', () => { const message = 'wrapper.setSelected() cannot be called on this element' - shouldThrowErrorOnElement('#label-el', message) - }) - function shouldThrowErrorOnElement (selector, message, value) { const wrapper = mountingMethod(ComponentWithInput) - const input = wrapper.find(selector) + const input = wrapper.find('#label-el') - const fn = () => input.setSelected(value) + const fn = () => input.setSelected('value') expect(fn) .to.throw() .with.property('message', '[vue-test-utils]: ' + message) - } + }) }) From cae60baf289425ba78f557569c9abc869cdca931 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Mon, 24 Dec 2018 21:34:47 +0000 Subject: [PATCH 3/5] refactor: update setValue --- packages/test-utils/src/wrapper.js | 16 +++++++++------- test/specs/wrapper/setSelected.spec.js | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index 723db187c..1262ccc1b 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -744,11 +744,7 @@ export default class Wrapper implements BaseWrapper { // $FlowIgnore const type = this.attributes().type - if (tagName === 'SELECT') { - // $FlowIgnore - this.element.value = value - this.trigger('change') - } else if (tagName === 'OPTION') { + if (tagName === 'OPTION') { throwError( `wrapper.setValue() cannot be called on an