Vue-test-utils: TypeError: Cannot read property '$el' of undefined

Created on 6 Sep 2018  ·  4Comments  ·  Source: vuejs/vue-test-utils

Version

1.0.0-beta.24

Reproduction link

https://codesandbox.io/s/7307xq2171

Steps to reproduce

Bump @vue/test-utils version from 1.0.0-beta.21 to any later/latest version to reproduce the bug on provided sandbox link.

What is expected?

There shouldn't be any error on console.

What is actually happening?

TypeError: Cannot read property '$el' of undefined.


This issue does not occur on 1.0.0-beta.21.

bug

Most helpful comment

This is caused by the synchronous Transition stub component that Vue Test Utils adds by default. You can turn it off with the stubs options:

mount(TestComponent, {
  stubs: {
    transition: false
  }
})

All 4 comments

It happened to me as well while upgrading from 1.0.0-beta.24 to 1.0.0-beta.25.

While running the tests I get:

  ● default › should match the snapshot

    TypeError: Cannot read property '$el' of undefined

      10 |
      11 |   it('should match the snapshot', () => {
    > 12 |     expect(vm.$el).toMatchSnapshot()
         |               ^
      13 |   })
      14 |
      15 |   it('should have link to the campaign list page', () => {

      at Object.<anonymous> (tests/unit/specs/views/NotFound.spec.js:12:15)

I put everything in a gist: https://gist.github.com/rhymes/9972f9259711035156545c00efae73c3

When solve this problem?Thanks

This is caused by the synchronous Transition stub component that Vue Test Utils adds by default. You can turn it off with the stubs options:

mount(TestComponent, {
  stubs: {
    transition: false
  }
})
import ElementUI from 'element-ui'
const localVue = createLocalVue()
localVue.use(ElementUI)

image

Was this page helpful?
5 / 5 - 1 ratings