Skip to content

Add Pinia plugin for actionsCompleted in unit tests

Erwan Rouchet requested to merge pinia-test-plugin into master

This adds a Pinia plugin and a test setup helper that provide multiple methods to wait for actions to be finished, just like how we used to do it with the Vuex store:

describe('something', () => {
  let pinia, store
  before('Setting up mocks', () => {
    [pinia] = setUpTestPinia([actionsCompletedPlugin])
    store = useSomethingStore()
  })

  it('waits for actions to be completed only in one store', async () => {
    await store.actionsCompleted()
  })

  it('waits for actions to be completed in any store', async () => {
    await pinia.actionsCompleted()
  })
})

I added the setUpTestPinia helper because setting up the Vue app and Pinia instance to work properly with plugins is tricky and very easy to mess up. It took me far longer to do the setting up than to write the plugin.

Edited by Erwan Rouchet

Merge request reports

Loading