Vue-test-utils: "Failed to resolve filter" while running tests

Created on 19 Apr 2018  ·  3Comments  ·  Source: vuejs/vue-test-utils

Version

1.0.0-beta.14

Reproduction link

https://jsfiddle.net/50wL7mdz/323724/

Steps to reproduce

Create a Vue project
Add a filter (like mine or a different one)
Test project with Jest and vue-test-utils

What is expected?

Test should run without any errors

What is actually happening?

Test are running, but throwing errors:

"[Vue warn]: Failed to resolve filter: si"


I have also tried importing Vue to the test spec file and setting up the filter there, but that didn't seem to help.

need repro

Most helpful comment

I can't reproduce this.

For me, registering a filter before mounting works as expected:

Vue.filter('aFilter', () => 'foo')

test('updates computed properties', () => {
  const wrapper = shallow(App)
  expect(wrapper.text()).toContain('foo')
})

All 3 comments

I can't reproduce this.

For me, registering a filter before mounting works as expected:

Vue.filter('aFilter', () => 'foo')

test('updates computed properties', () => {
  const wrapper = shallow(App)
  expect(wrapper.text()).toContain('foo')
})

OK, following this example and testing on a brand new build cleared things up. I must have made a mistake on my side. Thank you very much and sorry for the false report.

If you're using Nuxt or are using modular filter imports you can do this.

import "~/plugins/filters";
Was this page helpful?
0 / 5 - 0 ratings