dhershman1 / vue-debounce

A simple to use directive for debounce solutions
MIT License
172 stars 15 forks source link

Put some information for testing inside vue utils #55

Open Natega opened 3 years ago

Natega commented 3 years ago

Can you add some information on how to test a component with debounce directive. Thx

dhershman1 commented 3 years ago

Sorry, I've been swamped with work things to really look into this, so I'm still researching the best approach.

renaud-dev commented 1 year ago

@Natega FYI I just ended up building a mocked directive :

export const vueDebounceMockDirective = {
  created(el: any, binding: { value: (...args: any[]) => void }) {
    const debouncedFn = binding.value;

    el.addEventListener('input', (event: any) => {
      debouncedFn(event.target.value);
    });
  }
};

And I use it in my test like this :

// MountingOptions
options = {
  global: {
    // ...
    directives: {
      debounce: vueDebounceMockDirective
     }
 },

It works well using vue-test-utils setValue.

Good luck everyone ! And thank you @dhershman1 for the great lib !