How to test the layout method in Nuxt (Vue) with jest?

Viewed 505

I want to test the "layout" method in a Nuxt page. The structure is as below. I've simplified the code to better serve the question.

<template>

<!-- insert any dom here -->
</template>

<script>

export default {
  layout({ isDesktop }) {
    return `default/${isDesktop ? 'desktop' : 'mobile'}/index`;
  },
  head() {
    return {};
  },
  name: 'PageName',
  meta: {
      anyMetaProperty: true
  },
  data() {
let component = import( `~/path/to/the/child/component`);
    return {
      component,
    };
  },
};
</script>

I've successfully tested other parts of the code since they are similar to typical Vue component, but I had no luck with the "layout" method. I've tried accessing wrapper.vm.layout in the test, but it returns undefined. I also have tried mocking the method with jest.fn() mockReturnedValue function, but the method stays uncovered when I checked the coverage by running jest --coverage.

Any help would be appreciated. Thank you!

0 Answers
Related