menu

Testing Library

Simple and complete DOM testing utilities that encourage good testing practices.

Channels
Chat
view-forward
# All channels
view-forward
# General
view-forward
# General Help
view-forward
# Angular Help
view-forward
# Cypress Help
view-forward
# DOM Help
view-forward
# React Help
view-forward
# Svelte Help
view-forward
# TestCafe Help
view-forward
# Vue Help
view-forward
Team

mocking directives

October 31, 2019 at 5:04pm

mocking directives

October 31, 2019 at 5:04pm
My component is using directives and I get Failed to resolve directive. I added directives: { tooltip: jest.fn() }, to the options of the render function, but I still get this error.

November 1, 2019 at 9:53am
Hi! First thing that comes to my mind is that you could use the third parameter of render method, which returns the local Vue instance, to register your directive:
import myDirective from 'somewhere'
const { getByText } = render(Component, {}, vue => {
vue.directive('setText', myDirective)
})
If that works, would you like to provide an example test in Vue Testing Library repository? We don't have an example of testing a component with directives, and I feel it would be a great addition.
Hope it helps!
  • reply
  • like

November 3, 2019 at 4:52pm
Thanks a lot, I'll make that PR tomorrow
  • reply
  • like

November 4, 2019 at 6:57am
done! :D
  • reply
  • like