Skip to content

WIP feat(test-utils): support returning render function from setup #1512

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

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions packages/test-utils/src/mount.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default function mount(component, options = {}) {

const _Vue = createLocalVue(options.localVue)

if (component.setup) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be required

component.render = component.setup()
}

const mergedOptions = mergeOptions(options, config)

validateOptions(mergedOptions, component)
Expand Down
13 changes: 13 additions & 0 deletions test/specs/mount.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Vue from 'vue'
import { compileToFunctions } from 'vue-template-compiler'
import { mount, createLocalVue } from '@vue/test-utils'
import Component from '~resources/components/component.vue'
import CompositionAPI, { createElement } from '@vue/composition-api'
import ComponentWithProps from '~resources/components/component-with-props.vue'
import ComponentWithMixin from '~resources/components/component-with-mixin.vue'
import ComponentAsAClass from '~resources/components/component-as-a-class.vue'
Expand Down Expand Up @@ -413,6 +414,18 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
expect(wrapper.findAll(ChildComponent).length).to.equal(1)
})

it('works with composition api plugin', () => {
const localVue = createLocalVue()
localVue.use(CompositionAPI)
const Comp = {
setup() {
return () => createElement('div', 'composition api')
}
}
const wrapper = mount(Comp, { localVue })
expect(wrapper.html()).to.equal('<div>composition api</div>')
})

it('handles nested components with extends', () => {
const GrandChildComponent = {
template: '<div />',
Expand Down