testing-library / vue-testing-library

🦎 Simple and complete Vue.js testing utilities that encourage good testing practices.
http://testing-library.com/vue
MIT License
1.06k stars 110 forks source link

Unable to make mocking or stubs #291

Closed juancampuzano closed 1 year ago

juancampuzano commented 1 year ago

If I can't use shallow rendering, how do I mock out components in tests?

In the documentation there is a way to mock a feature, but this is only working in the following library: @testing-library/jest-dom

image

In the example you will see that it is importing the @testing-library/jest-dom library on line #2 instead using @testing-library/vue

Do I need to install that library to make the mocking? Or Is there a way to do it in the @testing-library/vue library?

juancampuzano commented 1 year ago

I found the error in the documentation you haven't the stubs property inside the global property

import {render} from '@testing-library/vue'
import Component from './Component'

test('Can stub components', () => {
  render(Component, {
     global: { stubs: ['FontAwesomeIcon'] },
  })
})
jasosims commented 1 year ago

@juancampuzano Thanks! I was stuck on this for quite awhile because the documentation is incorrect.

afontcu commented 1 year ago

nice catch! fancy to open up a PR in https://github.com/testing-library/testing-library-docs/blob/main/docs/vue-testing-library/faq.mdx fixing the issue?