I’m using Cypress in my Vue.js project (Nuxt.js). The main problem I can’t managed is how to understand the vuex store is ready. Let’s say I have a button that can call axios to fetch some data. Then the data came in to the store by mutations and Vue will render it in a template. The next element I want to interact with is empty before the store has built. But the cypress is trying to check it.
How to call next cypress action (like cy.get) after the store has built?
My project is more complicated. But the core problem is that cypress sometimes don’t wait for store building and trying to work further. For the first time we have used cy.wait(1000), but it seems not so perfect decision.
<div> <button data-cy="fetchDataBtn" @click="fetchData">get items</button> <ul> <li v-for="item in items"> <p>{{ item.title }}</p> <button @click="fetchProduct(item.id)" > buy {{ item.name }} </button> </li> </ul> </div> <script> import { mapState } from 'vuex'; export default { name: 'App', computed: { ...mapState('list', ['items']) } } </script> I expect the scenario below:
cy.get([‘data-cy=fetchDataBtn’]).click() // wait for store is ready and list is already rendered // (NOT cy.wait('GET', 'url_string') or cy.wait(milliseconds)) cy.contains(‘button’, 'buyItemName').click()