Skip to content

Commit

Permalink
fix(config): Do not use config.renderStubDefaultSlot
Browse files Browse the repository at this point in the history
* docs mention config.global.renderStubDefaultSlot
* get rid of double definition
  • Loading branch information
xanf committed Oct 15, 2022
1 parent 77bfbe2 commit e5b7c9c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
6 changes: 3 additions & 3 deletions docs/guide/advanced/stubs-shallow-mount.md
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
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
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
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
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

0 comments on commit e5b7c9c

Please sign in to comment.