From b679b27909c77975cd2a71c8fedc9caec10ba901 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Mon, 20 Jan 2020 20:05:56 +1000 Subject: [PATCH 1/2] feat: stub out transitions by default --- packages/create-instance/create-instance.js | 2 +- .../components/component-with-transitions.vue | 20 +++++++++++++++++++ test/specs/mounting-options/stubs.spec.js | 9 +++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/resources/components/component-with-transitions.vue diff --git a/packages/create-instance/create-instance.js b/packages/create-instance/create-instance.js index fb7cfc292..0b7345b31 100644 --- a/packages/create-instance/create-instance.js +++ b/packages/create-instance/create-instance.js @@ -55,7 +55,7 @@ export default function createInstance( const stubComponentsObject = createStubsFromStubsObject( componentOptions.components, // $FlowIgnore - options.stubs, + { ...options.stubs, transition: true }, _Vue ) diff --git a/test/resources/components/component-with-transitions.vue b/test/resources/components/component-with-transitions.vue new file mode 100644 index 000000000..9af326ce4 --- /dev/null +++ b/test/resources/components/component-with-transitions.vue @@ -0,0 +1,20 @@ + + + diff --git a/test/specs/mounting-options/stubs.spec.js b/test/specs/mounting-options/stubs.spec.js index df6efeebe..cd91a324d 100644 --- a/test/specs/mounting-options/stubs.spec.js +++ b/test/specs/mounting-options/stubs.spec.js @@ -1,4 +1,5 @@ import ComponentWithChild from '~resources/components/component-with-child.vue' +import ComponentWithTransitions from '~resources/components/component-with-transitions.vue' import ComponentWithNestedChildren from '~resources/components/component-with-nested-children.vue' import Component from '~resources/components/component.vue' import ComponentAsAClass from '~resources/components/component-as-a-class.vue' @@ -53,6 +54,14 @@ describeWithShallowAndMount('options.stub', mountingMethod => { expect(wrapper.findAll(Component).length).to.equal(1) }) + it('stubs out transitions by default', async () => { + const wrapper = mountingMethod(ComponentWithTransitions) + expect(wrapper.find('[data-testid="expanded"]').exists()).to.equal(true) + wrapper.setData({ expanded: true }) + await wrapper.vm.$nextTick() + expect(wrapper.find('[data-testid="expanded"]').exists()).to.equal(false) + }) + it('replaces component with a component', () => { const mounted = sandbox.stub() const Stub = { From d302bff40509b3a933bb067db1818467ea1a93b2 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Mon, 20 Jan 2020 21:18:32 +1000 Subject: [PATCH 2/2] fix: stub in global object --- packages/create-instance/create-instance.js | 2 +- packages/test-utils/src/config.js | 5 ++++- test/specs/config.spec.js | 9 +++++++++ test/specs/mounting-options/stubs.spec.js | 9 --------- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/create-instance/create-instance.js b/packages/create-instance/create-instance.js index 0b7345b31..fb7cfc292 100644 --- a/packages/create-instance/create-instance.js +++ b/packages/create-instance/create-instance.js @@ -55,7 +55,7 @@ export default function createInstance( const stubComponentsObject = createStubsFromStubsObject( componentOptions.components, // $FlowIgnore - { ...options.stubs, transition: true }, + options.stubs, _Vue ) diff --git a/packages/test-utils/src/config.js b/packages/test-utils/src/config.js index e70ea7c20..dca576c28 100644 --- a/packages/test-utils/src/config.js +++ b/packages/test-utils/src/config.js @@ -1,5 +1,8 @@ export default { - stubs: {}, + stubs: { + transition: true, + 'transition-group': true + }, mocks: {}, methods: {}, provide: {}, diff --git a/test/specs/config.spec.js b/test/specs/config.spec.js index 660aafabc..3f44751a1 100644 --- a/test/specs/config.spec.js +++ b/test/specs/config.spec.js @@ -1,6 +1,7 @@ import { describeWithShallowAndMount } from '~resources/utils' import ComponentWithProps from '~resources/components/component-with-props.vue' import { config, createLocalVue } from '@vue/test-utils' +import ComponentWithTransitions from '~resources/components/component-with-transitions.vue' describeWithShallowAndMount('config', mountingMethod => { const sandbox = sinon.createSandbox() @@ -90,4 +91,12 @@ describeWithShallowAndMount('config', mountingMethod => { }) expect(console.error).calledWith(sandbox.match('[Vue warn]')) }) + + it('stubs out transitions by default', async () => { + const wrapper = mountingMethod(ComponentWithTransitions) + expect(wrapper.find('[data-testid="expanded"]').exists()).to.equal(true) + wrapper.setData({ expanded: true }) + await wrapper.vm.$nextTick() + expect(wrapper.find('[data-testid="expanded"]').exists()).to.equal(false) + }) }) diff --git a/test/specs/mounting-options/stubs.spec.js b/test/specs/mounting-options/stubs.spec.js index cd91a324d..df6efeebe 100644 --- a/test/specs/mounting-options/stubs.spec.js +++ b/test/specs/mounting-options/stubs.spec.js @@ -1,5 +1,4 @@ import ComponentWithChild from '~resources/components/component-with-child.vue' -import ComponentWithTransitions from '~resources/components/component-with-transitions.vue' import ComponentWithNestedChildren from '~resources/components/component-with-nested-children.vue' import Component from '~resources/components/component.vue' import ComponentAsAClass from '~resources/components/component-as-a-class.vue' @@ -54,14 +53,6 @@ describeWithShallowAndMount('options.stub', mountingMethod => { expect(wrapper.findAll(Component).length).to.equal(1) }) - it('stubs out transitions by default', async () => { - const wrapper = mountingMethod(ComponentWithTransitions) - expect(wrapper.find('[data-testid="expanded"]').exists()).to.equal(true) - wrapper.setData({ expanded: true }) - await wrapper.vm.$nextTick() - expect(wrapper.find('[data-testid="expanded"]').exists()).to.equal(false) - }) - it('replaces component with a component', () => { const mounted = sandbox.stub() const Stub = {