Testing async component that gets data from store #814
-
Hi, I'm trying to write some tests for my components, however, unsuccessfully. My store is composed using Pinia. Customers component is an async component, so I'm wrapping it into the ShowCustomers component using Suspense. Customers component when created will check with pinia store to see if it should run fetchAll() method which sends out get request to api using axios. I'm mocking an axios get request to return a list of customers. My expectation: is that a test suite mounts ShowCustomers component then it mounts a Customers component into Suspend, waits until it gets resolved, which is Customers component calls an action fetchAll from customersStore, an axios get request is made and my mocked axios service responds with a list of customers. Then this list of Customers is shown inside a Customers component. What actually happens: Customers component is mounted, pinia store action fetchAll is called once as per expectation, however, this does not resolve state being updated. In fact, the axios get request is not executed. Customers.vue
Test:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
This is actually expected when using a testing pinia. You can use a regular pinia instance too or let the actions run like at https://github.com/posva/pinia/blob/v2/packages/testing/src/testing.spec.ts#L65 |
Beta Was this translation helpful? Give feedback.
This is actually expected when using a testing pinia. You can use a regular pinia instance too or let the actions run like at https://github.com/posva/pinia/blob/v2/packages/testing/src/testing.spec.ts#L65