Vue-test-utils: Buefy issue inside vue-test-utils

Created on 25 Sep 2018  路  4Comments  路  Source: vuejs/vue-test-utils

Version

1.0.0-beta.25

Reproduction link

https://github.com/EIREXE/buefy-bug

Steps to reproduce

What is expected?

That the test works without any extra error

What is actually happening?

The test errors out (and events such as @click don't work)

``` console.error node_modules/vue/dist/vue.runtime.common.js:589
[Vue warn]: Error in created hook: "Error: You should wrap bDropdownItem on a bDropdown"

found in

---> <BDropdownItem>
       <BDropdown>
         <PostItem>
           <Root>

console.error node_modules/vue/dist/vue.runtime.common.js:1739
Error: You should wrap bDropdownItem on a bDropdown
at VueComponent.created (/home/tarda/figuresite/frontend/node_modules/buefy/dist/buefy.js:5471:19)
```


This is a vue-test-utils exclusive error, so I believe buefy is not to blame here.

bug

Most helpful comment

The issue is caused by Vue Test Utils stubbing the Transition component. For now, you can fix the error by telling Vue Test Utils not to stub Transition:

const msg = 'new message'
const wrapper = mount(HelloWorld, {
  propsData: { msg },
  stubs: {
    transition: false
  }
})
expect(wrapper.find({ ref: 'a1b' }))

Unfortunately this means you will sometimes need to use Vue.nextTick to wait for the Transition component to re render:

it('renders props.msg when passed', (done) => {
  const wrapper = mount(HelloWorld, {
    stubs: {
      transition: false
    }
  })
  expect(wrapper.find({ ref: 'a1b' }))
  wrapper.trigger('click')
  Vue.nextTick(() => {
    assert(wrapper.text()).toBe('some text')
    done()
  })
})

This bug with the Transition stub will probably be fixed in the future after Vue 2.5.18 is released, by removing the Transition stub when Vue is running in sync mode.

Alternatively we could fix the TransitionStub component stub to stop the error.

All 4 comments

Forgot to add the particular error, it's done now...

The issue is caused by Vue Test Utils stubbing the Transition component. For now, you can fix the error by telling Vue Test Utils not to stub Transition:

const msg = 'new message'
const wrapper = mount(HelloWorld, {
  propsData: { msg },
  stubs: {
    transition: false
  }
})
expect(wrapper.find({ ref: 'a1b' }))

Unfortunately this means you will sometimes need to use Vue.nextTick to wait for the Transition component to re render:

it('renders props.msg when passed', (done) => {
  const wrapper = mount(HelloWorld, {
    stubs: {
      transition: false
    }
  })
  expect(wrapper.find({ ref: 'a1b' }))
  wrapper.trigger('click')
  Vue.nextTick(() => {
    assert(wrapper.text()).toBe('some text')
    done()
  })
})

This bug with the Transition stub will probably be fixed in the future after Vue 2.5.18 is released, by removing the Transition stub when Vue is running in sync mode.

Alternatively we could fix the TransitionStub component stub to stop the error.

That appears to fix it, thank you for providing a workaround in the meantime!

This is the same issue reported in #958, so I'll close this in favor of that issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robcresswell picture robcresswell  路  3Comments

38elements picture 38elements  路  3Comments

kjugi picture kjugi  路  3Comments

maerteijn picture maerteijn  路  3Comments

lusarz picture lusarz  路  3Comments