Skip to content

fix(config): Do not use config.renderStubDefaultSlot #1797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/guide/advanced/stubs-shallow-mount.md
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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 `<slot>` for a stubbed component
- use `global.renderStubDefaultSlot` to render the default `<slot>` for a stubbed component
2 changes: 1 addition & 1 deletion docs/migration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export interface GlobalConfigOptions {
DOMWrapper: Pluggable<DOMWrapper<Node>>
createStubs?: CustomCreateStub
}
renderStubDefaultSlot: boolean
/**
* @deprecated use global.
*/
renderStubDefaultSlot?: boolean
}

interface Plugin<Instance, O> {
Expand Down Expand Up @@ -80,6 +83,5 @@ export const config: GlobalConfigOptions = {
plugins: {
VueWrapper: new Pluggable(),
DOMWrapper: new Pluggable()
},
renderStubDefaultSlot: false
}
}
10 changes: 8 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [])],
Expand Down
8 changes: 4 additions & 4 deletions tests/mountingOptions/global.stubs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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']
Expand All @@ -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',
Expand Down