1

I have a Vue functional component, with some tests using Jest, but the coverage say 0 for this file. Is this the right way to test functional components in Vue?

this is an example of my component

<template functional>
      <div :class="['name', ...props.extraClasses]">
          {{ props.itemName }}
      </div>
</template>

<script>
export default {
    props: {
        itemName: {
            type: String,
            required: true,
        },
        extraClasses: {
            type: Array,
        },
    },
};
</script>

This is what 1 of my tests look like

test('it works correctly with all props', () => {

    const wrapper = shallow(cmp, {
        context: {
          props: {
            itemName: 'item name',
            extraClasses: ['extra1', 'extra2'],
          }
        },
      })
    const name = wrapper.find('.name');
    expect(name.classes()).toEqual(['name', 'extra1', 'extra2']);
    expect(name.text()).toBe('item name');
});

After I run jest, I'm seeing the coverage is 0, and the uncovered lines are the props. Is there any other way to test the functional component?

And how do I get the jest coverage to work correctly for this test file?

Thank you

1 Answer 1

1

this is reported to be fixed in version 4 https://github.com/vuejs/vue-jest/issues/88 I tried upgrading to [email protected] and confirmed this issue was fixed

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.