2

I have a component like this

<template>
  <p>{{ msg }}</p>
  <inner-comp></inner-comp>
</template>
<script>
  import InnerComp from './components/InnerComp .vue';
  export default {
    props: ['msg'],
    components: {
        innerComp : InnerComp 
    }
  }
</script>

and the unit test

import Vue from 'vue'
import MyComponent from './MyComponent.vue'
// helper function that mounts and returns the rendered text
function getRenderedText (Component, propsData) {
  const Ctor = Vue.extend(Component)
  const vm = new Ctor({ propsData }).$mount()
  return vm.$el.textContent
}
describe('MyComponent', () => {
  it('renders correctly with different props', () => {
    expect(getRenderedText(MyComponent, {
      msg: 'Hello'
    })).toBe('Hello')

  })
})

Test is passing, but it is throwing LOG ERROR like this

'[Vue warn]: Failed to mount component: template or render function not defined.
(found in <InnerComp>)'

1 Answer 1

1

Assuming you are using webpack, you should import component like

import Vue from 'vue'
import MyComponent from 'src/components/MyComponent.vue'

in your unit test file

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.