Testing Vue filters with jest

Posted by Editorial Staff | Updated on

If you’re writing filters used in multiple components, then it’s quite easy to test.

Since Vue.filter simply takes a function, you can just write a test for the function independently of the filter by exporting the definition, like so:

Then in your test file, import the function and test it like you do anything else:

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers