Are actions somehow async under the hood? #515
-
I have a notification component in my app, that reacts on changes in the store. Therefore if the state /**
* Show notification of certain type with message.
*/
showNotification(message: string) {
this.$patch({ visible: true, message });
}, I am testing my components with it('should show the notification message', () => {
const message = 'Hello World';
const { queryByText } = renderComponent(Notification);
notificationStore.showNotification(message) // returns void;
expect(queryByText(message)).toBeInTheDocument();
}); But it works when I do: it('should show the notification message', async () => {
const message = 'Hello World';
const { queryByText } = renderComponent(Notification);
await notificationStore.showNotification(message) // returns void;
expect(queryByText(message)).toBeInTheDocument();
}); I was wondering why it behaves like this. Could you help me with this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I think you need to wait one tick (nextTick) for the component to render. In pinia, actions are async if you make them async. They're not always wrapped with a promise like in Vuex |
Beta Was this translation helpful? Give feedback.
I think you need to wait one tick (nextTick) for the component to render.
In pinia, actions are async if you make them async. They're not always wrapped with a promise like in Vuex