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.07k stars 111 forks source link

Expose the `wrapper` instance in the `render` method #260

Closed elioschmutz closed 2 years ago

elioschmutz commented 2 years ago

Hey

Would be great having access to the underlying wrapper-object to get access to the vue-test-utils methods and properties.

Here is the diff that solved my problem:

diff --git a/node_modules/@testing-library/vue/dist/render.js b/node_modules/@testing-library/vue/dist/render.js
index b55fc18..5599956 100644
--- a/node_modules/@testing-library/vue/dist/render.js
+++ b/node_modules/@testing-library/vue/dist/render.js
@@ -80,6 +80,7 @@ function render(Component) {
   mountedWrappers.add(wrapper);
   container.appendChild(wrapper.element);
   return _objectSpread({
+    wrapper: wrapper,
     container: container,
     baseElement: baseElement,
     debug: function debug() {

This issue body was partially generated by patch-package.

afontcu commented 2 years ago

Hi! Thanks for opening the issue.

The question si quite similar to https://github.com/testing-library/vue-testing-library/pull/250, and the answer too :) In short: Vue Testing Library is a wrapper on top of Vue Test Utils that hides methods that do not align to the principles of the testing library family. 99% of what you might need to test in a component is available in Vue Testing Library, and for that special 1% the recommendation is to use Vue Test Utils directly.

Hope it helps!