From e5b7c9c65ddd48ed8c3c2360dd97ab548c16b3e1 Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Thu, 6 Oct 2022 13:56:04 +0300 Subject: [PATCH] fix(config): Do not use config.renderStubDefaultSlot * docs mention config.global.renderStubDefaultSlot * get rid of double definition --- docs/guide/advanced/stubs-shallow-mount.md | 6 +++--- docs/migration/index.md | 2 +- src/config.ts | 8 +++++--- src/utils.ts | 10 ++++++++-- tests/mountingOptions/global.stubs.spec.ts | 8 ++++---- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/docs/guide/advanced/stubs-shallow-mount.md b/docs/guide/advanced/stubs-shallow-mount.md index dc43fe98c..b9cdf4c1b 100644 --- a/docs/guide/advanced/stubs-shallow-mount.md +++ b/docs/guide/advanced/stubs-shallow-mount.md @@ -275,11 +275,11 @@ For this use case, you can use `config.renderStubDefaultSlot`, which will render import { config, mount } from '@vue/test-utils' beforeAll(() => { - config.renderStubDefaultSlot = true + config.global.renderStubDefaultSlot = true }) afterAll(() => { - config.renderStubDefaultSlot = false + config.global.renderStubDefaultSlot = false }) test('shallow with stubs', () => { @@ -316,4 +316,4 @@ So regardless of which mounting method you choose, we suggest keeping these guid - use `global.stubs` to replace a component with a dummy one to simplify your tests - use `shallow: true` (or `shallowMount`) to stub out all child components -- use `config.renderStubDefaultSlot` to render the default `` for a stubbed component +- use `global.renderStubDefaultSlot` to render the default `` for a stubbed component diff --git a/docs/migration/index.md b/docs/migration/index.md index 889335a1d..a3f72ef86 100644 --- a/docs/migration/index.md +++ b/docs/migration/index.md @@ -206,7 +206,7 @@ You can enable the old behavior like this: ```js import { config } from '@vue/test-utils' -config.renderStubDefaultSlot = true +config.global.renderStubDefaultSlot = true ``` ### `destroy` is now `unmount` to match Vue 3 diff --git a/src/config.ts b/src/config.ts index 63c507b19..779506e84 100644 --- a/src/config.ts +++ b/src/config.ts @@ -12,7 +12,10 @@ export interface GlobalConfigOptions { DOMWrapper: Pluggable> createStubs?: CustomCreateStub } - renderStubDefaultSlot: boolean + /** + * @deprecated use global. + */ + renderStubDefaultSlot?: boolean } interface Plugin { @@ -80,6 +83,5 @@ export const config: GlobalConfigOptions = { plugins: { VueWrapper: new Pluggable(), DOMWrapper: new Pluggable() - }, - renderStubDefaultSlot: false + } } diff --git a/src/utils.ts b/src/utils.ts index 23c10ea61..a348f4124 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -40,8 +40,14 @@ export function mergeGlobalProperties( const renderStubDefaultSlot = mountGlobal.renderStubDefaultSlot ?? - config?.renderStubDefaultSlot ?? - configGlobal?.renderStubDefaultSlot + (configGlobal.renderStubDefaultSlot || config?.renderStubDefaultSlot) ?? + false + + if (config.renderStubDefaultSlot === true) { + console.warn( + 'config.renderStubDefaultSlot is deprecated, use config.global.renderStubDefaultSlot instead' + ) + } return { mixins: [...(configGlobal.mixins || []), ...(mountGlobal.mixins || [])], diff --git a/tests/mountingOptions/global.stubs.spec.ts b/tests/mountingOptions/global.stubs.spec.ts index f7534b0f6..473b03604 100644 --- a/tests/mountingOptions/global.stubs.spec.ts +++ b/tests/mountingOptions/global.stubs.spec.ts @@ -731,11 +731,11 @@ describe('mounting options: stubs', () => { } afterEach(() => { - config.renderStubDefaultSlot = false + config.global.renderStubDefaultSlot = false }) it('renders only the default stub slot only behind flag', () => { - config.renderStubDefaultSlot = true + config.global.renderStubDefaultSlot = true const wrapper = mount(Component, { global: { @@ -750,7 +750,7 @@ describe('mounting options: stubs', () => { }) it('renders none of the slots on a stub', () => { - config.renderStubDefaultSlot = false + config.global.renderStubDefaultSlot = false const wrapper = mount(Component, { global: { stubs: ['ComponentWithSlots'] @@ -764,7 +764,7 @@ describe('mounting options: stubs', () => { }) it('renders the default slot of deeply nested stubs when renderStubDefaultSlot=true', () => { - config.renderStubDefaultSlot = true + config.global.renderStubDefaultSlot = true const SimpleSlot = { name: 'SimpleSlot',