Skip to content
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

Bug: cant get defineExpose data which nested in component #1855

Closed
priority3 opened this issue Nov 11, 2022 · 8 comments
Closed

Bug: cant get defineExpose data which nested in component #1855

priority3 opened this issue Nov 11, 2022 · 8 comments
Labels
bug Something isn't working needs reproduction

Comments

@priority3
Copy link

priority3 commented Nov 11, 2022

I have the component named Collapse and child component named CollapseItem

and the CollapseItem has the defineExpose

// CollapseItem.vue
<script setup lang="ts" >
const isActive = computed(() =>
  collapse?.activeNames.value.includes(props.name),
)
defineExpose({
  isActive,
})

Describe the bug

// I register `collapse-item` in the global
import {config,mount} from '@vue/test-utils'
import {Collapse,CollapseItem} from 'xxx'
config.global.stubs = {
	CollapseItem,
} 
const wrapper = mount(Collapse,{
	props: {
		activeNames: ['1']	
	},
	slots: {
		default:`
          <collapse-item name="1" title="title1">111</collapse-item>
          <collapse-item name="2" disabled>222</collapse-item>
        `,
	}
})
const vm = wrapper.vm
const collapseWrapper = wrapper.findComponent(OCollapse)
const collapseItemWrappers = collapseWrapper.findAllComponents(
  OCollapseItem,
) as VueWrapper<CollapseItemInstance>[]


// BUG there is fail, `isActive` is not in vm 
expect(collapseItemWrappers[0].vm.isActive).toBe(true)

image

the child component CollapseItem is just get props
image

To Reproduce

Expected behavior

Related information:

  • @vue/test-utils version: ^2.1.0
  • Vue version: ^3.2.41
  • node version: v16.14.2
  • npm (or yarn) version: 8.15.0
  • pnpm version: 7.13.4

Additional context

@priority3 priority3 added the bug Something isn't working label Nov 11, 2022
@cexbrayat
Copy link
Member

Hi @priority3

Can you make a small online repro so we can take a look? https://stackblitz.com/edit/vitest-dev-vitest-ledp6h?file=package.json&initialPath=__vitest__

@priority3
Copy link
Author

Hi @priority3

Can you make a small online repro so we can take a look? stackblitz.com/edit/vitest-dev-vitest-ledp6h?file=package.json&initialPath=__vitest__

oh, thanks for your reply,I had found that maybe this is my bad in coding by test

@spacedawwwg
Copy link

Hi @priority3
Can you make a small online repro so we can take a look? stackblitz.com/edit/vitest-dev-vitest-ledp6h?file=package.json&initialPath=__vitest__

oh, thanks for your reply,I had found that maybe this is my bad in coding by test

@priority3 What did you do to fix/change/workaround this, as I have hit the same issue that doing:

defineExpose({ videoRef })

and then using:

wrapper.vm.videoRef

No longer works

@cexbrayat
Copy link
Member

I think I know what's going on: there is a breaking change in Vue core v3.2.45, and we need to release a new version of VTU to work around it (see #1858 ).

You can stay on v3.2.44 if you are encountering this issue with VTU v2.2.1

@priority3
Copy link
Author

Hi @priority3
Can you make a small online repro so we can take a look? stackblitz.com/edit/vitest-dev-vitest-ledp6h?file=package.json&initialPath=__vitest__

oh, thanks for your reply,I had found that maybe this is my bad in coding by test

@priority3 What did you do to fix/change/workaround this, as I have hit the same issue that doing:

defineExpose({ videoRef })

and then using:

wrapper.vm.videoRef

No longer works

@spacedawwwg , it's strange that I make the mini repo , but it's work fine.🤔

@cexbrayat
Copy link
Member

@priority3 Your repro is accurate: it fails if you use Vue 3.2.45 😉

@priority3
Copy link
Author

@priority3 Your repro is accurate: it fails if you use Vue 3.2.45 😉

oh, I applied the corresponding version of vue(^3.2.44) and vtu(^2.2.1), but same error, let me find the way to reproduce it.🤒

@cexbrayat
Copy link
Member

We released VTU v2.2.2 which should help with people encountering an issue with defineExpose and Vue v3.2.45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs reproduction
Projects
None yet
Development

No branches or pull requests

3 participants