nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.08k stars 623 forks source link

Testing setup #786

Open themathmagician opened 3 years ago

themathmagician commented 3 years ago

Hi there I am missing up documentation for how to test the nuxt/content module. I am making a text based game, where I read metadata (frontmatter) into a vuex store. Inside the store, I can access the $contentfunction from this by calling:

const actorsContent = await this.$content('games', game, 'actors', {deep: true}).fetch()     

But when I try to run my jest test code, and call dispatch to have my method called

beforeEach(async () => {
    store = await NuxtStore.createStore()
    await store.dispatch('init')
  })

I get the following error message:

TypeError: this.$content is not a function

So, what should I do, to have $content injected into the this of the vuex store in my test? A small example of using the module with some kind of testing would be beautiful - I havent been able to locate any.

Best Agata

staszewski commented 3 years ago

Would be nice to have some docs about testing. Just started testing and I don't know where to start :( Any idea how to test asyncData and $content?