diff --git a/src/mount.ts b/src/mount.ts index 4fa1fe3fa..8deca1982 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -337,17 +337,6 @@ export function mount( const Parent = defineComponent({ name: 'VTU_ROOT', render() { - // https://github.com/vuejs/vue-test-utils-next/issues/651 - // script setup components include an empty `expose` array as part of the - // code generated by the SFC compiler. Eg a component might look like - // { expose: [], setup: [Function], render: [Function] } - // not sure why (yet), but the empty expose array causes events to not be - // correctly captured. - // TODO: figure out why this is happening and understand the implications of - // the expose rfc for Test Utils. - if (isObjectComponent(component)) { - delete component.expose - } return h(component, props, slots) } }) @@ -457,19 +446,13 @@ export function mount( const warnSave = console.warn console.warn = () => {} - // get `vm`. - // for some unknown reason, getting the `vm` for components using ` diff --git a/tests/components/ScriptSetup_Expose.vue b/tests/components/ScriptSetup_Expose.vue new file mode 100644 index 000000000..d2dc97d4b --- /dev/null +++ b/tests/components/ScriptSetup_Expose.vue @@ -0,0 +1,19 @@ + + + diff --git a/tests/expose.spec.ts b/tests/expose.spec.ts new file mode 100644 index 000000000..c4bcc4036 --- /dev/null +++ b/tests/expose.spec.ts @@ -0,0 +1,40 @@ +import { mount } from '../src' +import Hello from './components/Hello.vue' +import DefineExpose from './components/DefineExpose.vue' +import ScriptSetupExpose from './components/ScriptSetup_Expose.vue' +import ScriptSetup from './components/ScriptSetup.vue' + +describe('expose', () => { + it('access vm on simple components', async () => { + const wrapper = mount(Hello) + + expect(wrapper.vm.msg).toBe('Hello world') + }) + + it('access vm on simple components with custom `expose`', async () => { + const wrapper = mount(DefineExpose) + + // other is exposed vie `expose` + expect(wrapper.vm.other).toBe('other') + // can access `msg` even if not exposed + expect(wrapper.vm.msg).toBe('Hello world') + }) + + it('access vm with