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

Vue Testing Library: Property 'updateProps' does not exist on type 'RenderResult' / rerender not updating props #262

Closed
linkurzweg opened this issue Jan 27, 2022 · 3 comments

Comments

@linkurzweg
Copy link

Hello! I am trying to test a Modal component in my Vue project. I want to test if the modal is rendered when the corresponding prop is set to true. The documentation states that the render result from Vue Testing Library should expose a helper method called updateProps. But it doesn't, I get an error that it does not exist when I try to use it:

image

So I don't know if the documentation is wrong or this is a bug in the library. One or the other should be corrected, I think.
I then instead tried to use the rerender method, but it does not seem to work:

Relevant code or config:

it('renders the modal when modelValue is changed to true ', async () => {
  const { queryByTestId, rerender } = render(UnverifiedFilesModal, {
    global: {
      plugins: [createTestingPinia()],
    },
    props: {
      modelValue: false,
    },
  })

  const modal = queryByTestId('unverified-files-modal')
  expect(modal).not.toBeInTheDocument()
  await rerender({ modelValue: true })
  expect(modal).toBeInTheDocument()
})

I get the error that element could not be found:

Error: expect(received).toBeInTheDocument()

received value must be an HTMLElement or an SVGElement.
Received has value: null

If I render the component with the prop initially set to true, it gets rendered without problems. But rerendering with the updated prop does not work. Any help would be very appreciated!

@afontcu afontcu transferred this issue from testing-library/dom-testing-library Jan 27, 2022
@afontcu
Copy link
Member

afontcu commented Jan 27, 2022

Hi,

looks like you're using Vue 3 version of Vue Testing Library, but docs are focused on the Vue 2 version. We'll update them as soon as Vue 3 versions gets out of beta, so for now you should trust TS and its types instead of docs. Check out #176 for additional changes between Vue 2 and Vue 3 versions

@linkurzweg
Copy link
Author

@afontcu Thanks! You're right, I'm using the Vue 3 version, didn't think about that. Any tips on how I should go about checking updating the props/emitting the value of my component?

@DannyFeliz
Copy link

For those looking for how to upgrade props, updateProps is now called rerender in Vue 3 to align with other Testing Lib libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants