In the previous lesson you used the Pinia stores in passing, as part of a view's journey: RoomDetailView called loadRooms and LoginView called signIn, and we checked what appeared on screen. But Colmena's most delicate logic is not in the views; it is in the stores: the catalogue's five-minute cache and its protection against duplicate requests, the creation of bookings that the API may reject because of an overlap, the optimistic cancellation that is rolled back if the API fails, the filter that decides which bookings a member sees and which a manager sees, and the persistence of the session and of the bookings cache. That logic has no interface, so the most direct and precise way of testing it is to use the store without any component. In this lesson you will learn to prepare a clean Pinia for each test, to check the state, getters and actions of Colmena's three stores, to test the persistence plugin, to mount components with stores prepared to measure thanks to createTestingPinia, and to test composables, both those that can be called directly and those that need a component to host them.

Contents

  1. A store is logic without an interface
  2. Preparing each test: a new Pinia and the mocked API
  3. useRoomsStore: state, getters and the catalogue cache
  4. useBookingsStore: creating, cancelling and filtering bookings
  5. useSessionStore: signing in and signing out
  6. Testing the persistence plugin
  7. Components that use stores: createTestingPinia
  8. Testing composables
  9. Which strategy to use for each piece
  10. Try it

  1. A store is logic without an interface

A Pinia setup store is, in essence, a function that creates refs, computeds and functions, and returns them. None of that needs a template to work: you can create the store, call its actions and read its state and its getters as you would with any JavaScript object. That makes stores the easiest pieces to test thoroughly in a Vue application:

Testing the logic through a view Testing the store directly
You have to mount the view, its children and its plugins Creating the store is enough
You only see the effects the view renders You have access to the whole state and all the getters
Edge cases (a race between two requests, a rollback) are hard to provoke from the interface They are provoked by calling the actions in the exact order
If it fails, you do not know whether the problem is in the view or in the store The failure points to the store

This does not replace the tests from the previous lesson, which check that the view and the store fit together. They are complementary: the store's tests test the rule (the cancellation is rolled back if the API fails) and the view's tests test the presentation (the "It has been restored" notice appears).

  1. Preparing each test: a new Pinia and the mocked API

When useBookingsStore() is called outside a component, Pinia needs to know which Pinia instance the store belongs to. In the application, that instance is activated by app.use(pinia); in a test, it is activated by hand with setActivePinia:

import { beforeEach, vi } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'

vi.mock('@/api')

beforeEach(() => {
  setActivePinia(createPinia()) // each test, with freshly created stores
  vi.resetAllMocks()            // and with the API mocks empty
})
  • createPinia() creates a new instance, without any store. setActivePinia makes it the active one: from then on, useRoomsStore() creates the store inside that instance the first time it is called and returns the same one on subsequent calls.
  • In beforeEach, so that each test starts from scratch. If they all shared a Pinia, the bookings created in one test would appear in the next one, and the catalogue cache would mean the second test never got to call the API.
  • vi.mock('@/api'), as in 08-02: the three stores import api from @/api, so none of them will reach the simulated API "for real", with its delays and its random failures.
  • This Pinia has no plugins (in main.js we add persistence to it). That is what we want: that way, the logic tests neither read nor write localStorage. Persistence is tested separately, in section 6.

Two Pinia tools we will use to prepare the starting state:

  • store.$patch({ ... }) assigns several state properties at once. It is the quick way of saying "start from a store that already has these bookings", without going through the API.
  • store.$state returns the complete state, useful for comparing it in one go with toEqual.

  1. useRoomsStore: state, getters and the catalogue cache

Let's recall the contract of useRoomsStore from 05-07: loadRooms({ force }) loads the catalogue unless there is a copy less than five minutes old, reuses the request in progress and never rejects (the error stays in error). The cache depends on time (Date.now()), so we will test it with the fake timers from the previous lesson. Create src/stores/__tests__/rooms.spec.js:

// src/stores/__tests__/rooms.spec.js
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'
import { api } from '@/api'
import { errorWithStatus } from '@/api/simulation.js'
import { rooms } from '@/data/rooms.js'
import { useRoomsStore } from '@/stores/rooms.js'

vi.mock('@/api')

describe('useRoomsStore', () => {
  beforeEach(() => {
    setActivePinia(createPinia())
    vi.resetAllMocks()
    vi.useFakeTimers()
    vi.setSystemTime(new Date(2026, 10, 3, 9, 0))
    // Each call returns a new copy, like the real API
    vi.mocked(api.rooms.fetchRooms).mockImplementation(async () => structuredClone(rooms))
  })

  afterEach(() => {
    vi.useRealTimers()
  })

  it('starts empty and not loading', () => {
    const roomsStore = useRoomsStore()

    expect(roomsStore.rooms).toEqual([])
    expect(roomsStore.loadedAt).toBeNull()
    expect(roomsStore.loading).toBe(false)
  })

  it('loads the catalogue and reuses it for five minutes', async () => {
    const roomsStore = useRoomsStore()

    await roomsStore.loadRooms()
    expect(roomsStore.rooms).toHaveLength(5)
    expect(roomsStore.loadedAt).toBe(new Date(2026, 10, 3, 9, 0).getTime())

    vi.advanceTimersByTime(4 * 60 * 1000) // 4 minutes later: fresh copy
    await roomsStore.loadRooms()
    expect(api.rooms.fetchRooms).toHaveBeenCalledTimes(1)

    vi.advanceTimersByTime(60 * 1000)     // 5 minutes: the copy has expired
    await roomsStore.loadRooms()
    expect(api.rooms.fetchRooms).toHaveBeenCalledTimes(2)
  })

  it('requests the catalogue again if forced to', async () => {
    const roomsStore = useRoomsStore()

    await roomsStore.loadRooms()
    await roomsStore.loadRooms({ force: true })

    expect(api.rooms.fetchRooms).toHaveBeenCalledTimes(2)
  })

  it('does not duplicate a request that is already in progress', async () => {
    const roomsStore = useRoomsStore()

    const first = roomsStore.loadRooms()
    const second = roomsStore.loadRooms() // while the first is still in flight
    expect(roomsStore.loading).toBe(true)

    await Promise.all([first, second])

    expect(api.rooms.fetchRooms).toHaveBeenCalledTimes(1)
    expect(roomsStore.loading).toBe(false)
  })

  it('stores the error without rejecting if the API fails', async () => {
    vi.mocked(api.rooms.fetchRooms).mockRejectedValue(
      errorWithStatus('Could not connect to the Colmena server', 503, 'connection')
    )
    const roomsStore = useRoomsStore()

    await expect(roomsStore.loadRooms()).resolves.toBeUndefined()

    expect(roomsStore.error).toBe('Could not connect to the Colmena server')
    expect(roomsStore.loadedAt).toBeNull()
    expect(roomsStore.loading).toBe(false)
  })

  it('offers the available rooms and lookup by id', async () => {
    const roomsStore = useRoomsStore()
    await roomsStore.loadRooms()

    expect(roomsStore.availableRooms.map((r) => r.id)).not.toContain('enjambre')
    expect(roomsStore.roomById('celda').capacity).toBe(1)
    expect(roomsStore.roomById('basement')).toBeUndefined()
  })
})

Let's analyse the decisions:

  • mockImplementation(async () => structuredClone(rooms)) instead of mockResolvedValue(rooms): with mockResolvedValue, every call would return the same array, and if a test modified a room in the store, it would be modifying the object the next call will receive. The implementation creates a copy on every call, as the real fetchRooms does.
  • vi.advanceTimersByTime also moves Date.now(): with fake timers, Date's time moves forward together with the timers'. That way we check both sides of the five-minute limit without waiting a single real second. Testing just either side of a limit is a classic technique: bugs tend to hide in the < that should have been <=.
  • The duplicate request: we call twice without an await in between, which is what happens when HomeView and DashboardBookingsView request the catalogue at the same time. The test checks what matters: that the API receives only one request. (Do not compare the two promises with toBe: Pinia wraps every call to an action so that it can notify $onAction, so each call returns a different promise, even though both wait for the same request.)
  • resolves.toBeUndefined() checks the design promise "never rejects": whoever calls loadRooms does not need a try/catch, and the error is looked up in the state.
  • The error is stored as a message (e.message), as the store was left in 05-06. If you applied the improvement we proposed at the end of 07-03 (storing the whole error in order to translate it), change that assertion to expect(roomsStore.error).toMatchObject({ code: 'connection' }).

  1. useBookingsStore: creating, cancelling and filtering bookings

4.1 Test data

The test bookings follow the course's model. A factory, like createRoom in 08-01, saves us repeating the ten fields in every test:

// src/stores/__tests__/bookings.spec.js (beginning of the file)
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'
import { api } from '@/api'
import { errorWithStatus } from '@/api/simulation.js'
import { useBookingsStore } from '@/stores/bookings.js'
import { useSessionStore } from '@/stores/session.js'

vi.mock('@/api')

function createTestBooking(changes = {}) {
  return {
    id: 'r-1', roomId: 'polen', date: '2026-11-03', startTime: '10:00', endTime: '12:00',
    member: 'Laura Gómez', attendees: 3, status: 'confirmed', extraEquipment: [], notes: '',
    ...changes
  }
}

// Leaves the store with these bookings, without going through the API
function withBookings(bookingsStore, list) {
  bookingsStore.$patch({
    byId: Object.fromEntries(list.map((b) => [b.id, b])),
    ids: list.map((b) => b.id)
  })
}

withBookings builds the normalised state (byId + ids) from 05-05 from a list. It is the only part of the tests that knows that internal structure: if it ever changed, only this helper would have to be updated. The assertions, on the other hand, will use the public getters (bookings, bookingById, myBookings).

4.2 createBooking: success and a 409 error

describe('useBookingsStore', () => {
  beforeEach(() => {
    setActivePinia(createPinia())
    vi.resetAllMocks()
  })

  describe('createBooking', () => {
    it('adds the booking the API returns, with its id, and returns it', async () => {
      const data = createTestBooking({ id: 'form-id' })
      const created = createTestBooking({ id: 'server-id' })
      vi.mocked(api.bookings.createBooking).mockResolvedValue(created)
      const bookingsStore = useBookingsStore()

      const result = await bookingsStore.createBooking(data)

      expect(api.bookings.createBooking).toHaveBeenCalledWith(data)
      expect(result).toEqual(created)
      expect(bookingsStore.bookingById('server-id')).toEqual(created)
      expect(bookingsStore.bookingById('form-id')).toBeNull()
    })

    it('rejects with the API error and adds nothing if there is an overlap', async () => {
      vi.mocked(api.bookings.createBooking).mockRejectedValue(
        errorWithStatus('The Polen Room is already booked', 409, 'overlap', { room: 'Polen Room' })
      )
      const bookingsStore = useBookingsStore()

      await expect(bookingsStore.createBooking(createTestBooking())).rejects.toMatchObject({
        status: 409,
        code: 'overlap'
      })
      expect(bookingsStore.bookings).toEqual([])
    })
  })

  // ... the other describe blocks in this section, in here
})
  • The server's id wins: in 05-02 we decided that the API assigns the identifier and that whoever creates the booking must use the one the API returns. The test pins this down: the store saves the booking with server-id, and there is none with the id the form brought. BookingView depends on this to take the user to the dashboard with ?new=.
  • The rejection is propagated: unlike loadRooms, createBooking does reject, because whoever calls it (the form) needs to know it has failed in order to show the error and not reset itself. The test checks both things: that the error arrives with its status and its code (the ones translateError will use) and that the store is not left with a phantom booking.

4.3 cancelBooking: optimistic and with a rollback

Optimistic cancellation is the most delicate logic in the store. Let's go over its sequence from 05-05:

sequenceDiagram
    participant P as Test
    participant S as useBookingsStore
    participant A as API (mocked)
    P->>S: cancelBooking('r-1')
    S->>S: operations['r-1'] = 'cancelling'
    S->>S: status = 'cancelled' (instantly)
    S->>A: cancelBooking('r-1')
    Note over P,S: The test checks the intermediate state
    A-->>S: rejects (503)
    S->>S: status = 'confirmed' (rollback)
    S->>S: deletes operations['r-1']
    S-->>P: rejects with the error

To check the intermediate state (the booking already appears cancelled, but the API has not responded yet), we need the API to "keep thinking" until we decide: it is the controlled promise from 08-02.

describe('cancelBooking', () => {
  it('cancels instantly and rolls back if the API fails', async () => {
    const { promise, reject } = Promise.withResolvers()
    vi.mocked(api.bookings.cancelBooking).mockReturnValue(promise)
    const bookingsStore = useBookingsStore()
    withBookings(bookingsStore, [createTestBooking()])

    const cancellation = bookingsStore.cancelBooking('r-1')

    // Before the API responds: optimistic
    expect(bookingsStore.bookingById('r-1').status).toBe('cancelled')
    expect(bookingsStore.isCancelling('r-1')).toBe(true)
    expect(bookingsStore.activeBookings).toHaveLength(0)

    reject(errorWithStatus('Could not connect to the Colmena server', 503, 'connection'))

    // After the failure: rollback
    await expect(cancellation).rejects.toMatchObject({ status: 503 })
    expect(bookingsStore.bookingById('r-1').status).toBe('confirmed')
    expect(bookingsStore.isCancelling('r-1')).toBe(false)
  })

  it('applies the server version if the API confirms', async () => {
    vi.mocked(api.bookings.cancelBooking).mockResolvedValue(createTestBooking({ status: 'cancelled' }))
    const bookingsStore = useBookingsStore()
    withBookings(bookingsStore, [createTestBooking()])

    await bookingsStore.cancelBooking('r-1')

    expect(bookingsStore.bookingById('r-1').status).toBe('cancelled')
    expect(bookingsStore.operations).toEqual({})
  })

  it('ignores a second cancellation while the first is in progress', () => {
    vi.mocked(api.bookings.cancelBooking).mockReturnValue(new Promise(() => {})) // never responds
    const bookingsStore = useBookingsStore()
    withBookings(bookingsStore, [createTestBooking()])

    bookingsStore.cancelBooking('r-1')
    bookingsStore.cancelBooking('r-1') // double click

    expect(api.bookings.cancelBooking).toHaveBeenCalledTimes(1)
  })
})
  • The first test walks through the diagram step by step: it calls the action without await (to stay in the middle), checks the optimistic state, provokes the failure with reject and only then waits for the action with rejects, which lets the rollback finish.
  • An empty activeBookings in the intermediate state confirms that the optimistic change propagates to the derived getters: it is what makes the booking disappear from the list of active ones instantly.
  • The third test protects the if (... || operations.value[id]) return guard against a double click. With a promise that never resolves, the first cancellation stays "in flight" for ever; the test does not need to wait for anything.

4.4 myBookings: depending on the role

myBookings queries useSessionStore() inside its computed property (05-07). In the test, both stores live in the same Pinia, so it is enough to change the session and read the getter:

describe('myBookings', () => {
  it('shows each member only their own, and a manager all of them, sorted', () => {
    const bookingsStore = useBookingsStore()
    const session = useSessionStore()
    withBookings(bookingsStore, [
      createTestBooking({ id: 'a', date: '2026-11-05' }),
      createTestBooking({ id: 'b', member: 'Marta Vidal' }),
      createTestBooking({ id: 'c', date: '2026-11-01' })
    ])

    expect(bookingsStore.myBookings).toEqual([]) // no session, none

    session.$patch({ name: 'Laura Gómez', email: '[email protected]', role: 'member' })
    expect(bookingsStore.myBookings.map((b) => b.id)).toEqual(['c', 'a'])

    session.$patch({ name: 'Marta Vidal', email: '[email protected]', role: 'manager' })
    expect(bookingsStore.myBookings.map((b) => b.id)).toEqual(['c', 'b', 'a'])
  })
})
  • $patch on the session prepares the state without going through signIn (and therefore without calling the API). To test myBookings we do not care how the session was started, only who has it.
  • .map((b) => b.id) turns the list into something easy to compare and to read when it fails: ['c', 'a'] says at once which bookings appear and in what order (c, on the 1st, before a, on the 5th).
  • Reactivity works just as in a component: when the session changes, the getter is recalculated. The manager case also confirms that the filtering and the sorting are independent.

  1. useSessionStore: signing in and signing out

signIn authenticates with the API, stores the member's details and starts loading the bookings in the background; signOut clears the session and empties the bookings store so as not to leave the previous member's data behind. Create src/stores/__tests__/session.spec.js:

// src/stores/__tests__/session.spec.js
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'
import { api } from '@/api'
import { errorWithStatus } from '@/api/simulation.js'
import { useSessionStore } from '@/stores/session.js'
import { useBookingsStore } from '@/stores/bookings.js'

vi.mock('@/api')

const MARTA = { name: 'Marta Vidal', email: '[email protected]', plan: 'business', role: 'manager' }

describe('useSessionStore', () => {
  beforeEach(() => {
    setActivePinia(createPinia())
    vi.resetAllMocks()
    // The bookings load that signIn triggers (and the catalogue it requests in parallel)
    vi.mocked(api.bookings.fetchBookings).mockResolvedValue([])
    vi.mocked(api.rooms.fetchRooms).mockResolvedValue([])
  })

  it('signs in with the member details and starts loading their bookings', async () => {
    vi.mocked(api.session.authenticate).mockResolvedValue({ ...MARTA })
    const session = useSessionStore()
    expect(session.active).toBe(false)

    await session.signIn('[email protected]', 'colmena')

    expect(api.session.authenticate).toHaveBeenCalledWith('[email protected]', 'colmena')
    expect(session.$state).toEqual(MARTA)
    expect(session.active).toBe(true)
    expect(session.isManager).toBe(true)
    expect(api.bookings.fetchBookings).toHaveBeenCalledTimes(1)
  })

  it('rejects incorrect credentials and does not start the session', async () => {
    vi.mocked(api.session.authenticate).mockRejectedValue(
      errorWithStatus('Incorrect email or password', 401, 'credentials')
    )
    const session = useSessionStore()

    await expect(session.signIn('[email protected]', 'bee')).rejects.toThrow(
      'Incorrect email or password'
    )
    expect(session.active).toBe(false)
    expect(api.bookings.fetchBookings).not.toHaveBeenCalled()
  })

  it('empties the bookings as well when signing out', () => {
    const session = useSessionStore()
    const bookingsStore = useBookingsStore()
    session.$patch({ ...MARTA })
    bookingsStore.$patch({
      byId: { a: { id: 'a', roomId: 'nectar', date: '2026-11-03', startTime: '10:00', member: 'Marta Vidal', status: 'confirmed' } },
      ids: ['a']
    })

    session.signOut()

    expect(session.active).toBe(false)
    expect(session.role).toBe('member')
    expect(bookingsStore.bookings).toEqual([])
  })
})
  • session.$state compares the four state fields in one go with the ones the API returned.
  • "Starts loading their bookings": signIn calls loadBookings() without await, so the test cannot wait for it to finish through the action. But it can check the observable effect we are interested in: the request to the API has gone out. The call to the API is recorded at the moment it is made, even if its response arrives later.
  • The error case checks what must not happen: no active session and no bookings load. Tests of "what does not happen" are as valuable as tests of what does: they guard against side effects that creep in over time.
  • signOut spans two stores. The test prepares both with $patch and checks the result in both: the rule "no data from the previous member must remain" from 05-07 is kept under watch.

  1. Testing the persistence plugin

6.1 Why it needs an application

The persistence plugin from 05-07 restores the saved state when a store is created and saves it on every change, according to each store's persistence option. To test it, you have to create a Pinia with the plugin. And here a subtlety comes up: Pinia keeps the plugins added with pinia.use() and only starts applying them once the instance is installed in an application with app.use(pinia). With just setActivePinia(createPinia().use(persistence)), the stores would be created without the plugin and the tests would fail for no apparent reason. An empty application is enough:

// Pinia with the persistence plugin, active and applied
function createPiniaWithPersistence() {
  const pinia = createPinia()
  pinia.use(persistence)
  createApp({}).use(pinia) // without this, Pinia does not apply its plugins
  setActivePinia(pinia)
  return pinia
}

6.2 Storage in jsdom

jsdom implements localStorage and sessionStorage for real, in memory. That has an advantage (the plugin works without mocking anything) and a danger: whatever is saved in one test is still there in the next one within the same file. That is why each persistence test starts by emptying them. Create src/stores/__tests__/persistence.spec.js:

// src/stores/__tests__/persistence.spec.js
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { createApp } from 'vue'
import { setActivePinia, createPinia } from 'pinia'
import { persistence } from '@/stores/plugins/persistence.js'
import { useSessionStore } from '@/stores/session.js'
import { useBookingsStore } from '@/stores/bookings.js'

// The stores import the API, even though we do not use it here
vi.mock('@/api')

function createPiniaWithPersistence() {
  const pinia = createPinia()
  pinia.use(persistence)
  createApp({}).use(pinia)
  setActivePinia(pinia)
  return pinia
}

describe('persistence plugin', () => {
  beforeEach(() => {
    sessionStorage.clear()
    localStorage.clear()
  })

  it('saves the session in sessionStorage when it changes', () => {
    createPiniaWithPersistence()
    const session = useSessionStore()

    session.$patch({ name: 'Laura Gómez', email: '[email protected]' })

    expect(JSON.parse(sessionStorage.getItem('colmena-session'))).toEqual({
      name: 'Laura Gómez',
      email: '[email protected]',
      plan: 'flexible',
      role: 'member'
    })
  })

  it('restores the saved session when the store is created', () => {
    sessionStorage.setItem(
      'colmena-session',
      JSON.stringify({ name: 'Marta Vidal', email: '[email protected]', plan: 'business', role: 'manager' })
    )
    createPiniaWithPersistence()

    const session = useSessionStore()

    expect(session.active).toBe(true)
    expect(session.isManager).toBe(true)
  })

  it('discards corrupted data', () => {
    sessionStorage.setItem('colmena-session', '{this is not JSON')
    createPiniaWithPersistence()

    const session = useSessionStore()

    expect(session.active).toBe(false)
    expect(sessionStorage.getItem('colmena-session')).toBeNull()
  })

  it('saves only byId and ids from the bookings', () => {
    createPiniaWithPersistence()
    const bookingsStore = useBookingsStore()

    bookingsStore.$patch({ byId: { a: { id: 'a' } }, ids: ['a'], loading: true })

    const saved = JSON.parse(localStorage.getItem('colmena-cache-bookings'))
    expect(Object.keys(saved)).toEqual(['byId', 'ids'])
  })
})
  • "Saves" checks the contract of the persisted data: the key (colmena-session), the storage (sessionStorage, which is cleared when the tab is closed) and the four fields. In 05-07 we stressed that this format is a contract with previous versions: this test will warn you if someone changes it by accident.
  • "Restores" prepares the storage before creating the store, which is when the plugin reads it. It is what happens when the page is reloaded with the session open.
  • "Discards corrupted data" protects the plugin's try/catch: an unreadable value must not stop the application from starting.
  • "Saves only byId and ids": loading is not persisted. If it slipped through, a reload in the middle of a load would leave the application with an eternal "Loading...".

  1. Components that use stores: createTestingPinia

7.1 The problem

In 08-02 we tested RoomDetailView with the real store and the mocked API. It is a good integration test, but for some components it is awkward: for DashboardBookingsView to show three bookings belonging to two members, one of them cancelled, with the catalogue already loaded and Laura signed in, you would have to configure several API responses, sign in and wait for the loads. And to check that the "Cancel" button does the right thing, the real store would run the whole optimistic cancellation, which we have already tested in section 4.

When what you want to test is the component (what it renders from a given state and which actions it dispatches), the official @pinia/testing package offers an alternative:

npm install -D @pinia/testing

7.2 What createTestingPinia does

createTestingPinia(options) creates a Pinia designed for component tests:

Option What it does In Colmena
initialState The initial state of each store, by its id { session: {...}, rooms: {...}, bookings: {...} }
stubActions (true by default) Replaces all the actions with mock functions that do nothing loadBookings and cancelBooking do not call the API
createSpy The function used to create those spies vi.fn (required if you do not use Vitest's globals)
plugins Pinia plugins to apply Normally none

In addition, the getters are real (they are calculated from the initial state) but they can be overridden by assigning them a value in the test, something impossible with a normal store. And as createTestingPinia activates itself, after mounting you can call useBookingsStore() in the test and you will get the same store the component uses, with its actions turned into spies.

7.3 DashboardBookingsView

Let's recall what the "My bookings" view does after modules 5 to 7: on mounting it calls bookingsStore.loadBookings(); it shows myBookings (via storeToRefs) with their formatted date, the room's name (from the rooms store) and their badge; each booking that is not cancelled has a "Cancel" button that asks for confirmation with window.confirm and calls bookingsStore.cancelBooking(id), and if it fails, it shows a translated notice. It also uses useRoute, useRouter, useI18n, useFormat, <i18n-t> and RouterLink, so we will mount it with the in-memory router. Create src/views/dashboard/__tests__/DashboardBookingsView.spec.js:

// src/views/dashboard/__tests__/DashboardBookingsView.spec.js
import { describe, it, expect, vi, afterEach } from 'vitest'
import { flushPromises } from '@vue/test-utils'
import { createTestingPinia } from '@pinia/testing'
import { mountWithPlugins } from '@tests/mount.js'
import { createTestRouter } from '@tests/router.js'
import { useBookingsStore } from '@/stores/bookings.js'
import { errorWithStatus } from '@/api/simulation.js'
import { rooms } from '@/data/rooms.js'
import DashboardBookingsView from '../DashboardBookingsView.vue'

function createTestBooking(changes) {
  return {
    id: 'r-1', roomId: 'polen', date: '2026-11-03', startTime: '10:00', endTime: '12:00',
    member: 'Laura Gómez', attendees: 3, status: 'confirmed', extraEquipment: [], notes: '',
    ...changes
  }
}

function initialState() {
  const list = [
    createTestBooking({ id: 'r-demo-1' }),
    createTestBooking({ id: 'r-demo-2', roomId: 'nectar', member: 'Marta Vidal', status: 'pending' }),
    createTestBooking({ id: 'r-demo-3', roomId: 'panal', date: '2026-11-07', status: 'cancelled' })
  ]
  return {
    session: { name: 'Laura Gómez', email: '[email protected]', plan: 'flexible', role: 'member' },
    rooms: { rooms: structuredClone(rooms), loadedAt: Date.now() },
    bookings: { byId: Object.fromEntries(list.map((b) => [b.id, b])), ids: list.map((b) => b.id) }
  }
}

async function mountDashboard(piniaOptions = {}) {
  const router = await createTestRouter('/dashboard/bookings')
  const wrapper = mountWithPlugins(DashboardBookingsView, {
    router,
    global: {
      plugins: [createTestingPinia({ createSpy: vi.fn, initialState: initialState(), ...piniaOptions })]
    }
  })
  return { wrapper, bookingsStore: useBookingsStore() }
}

describe('DashboardBookingsView', () => {
  afterEach(() => {
    vi.restoreAllMocks()
  })

  it('requests the bookings on mounting and shows only the member’s own', async () => {
    const { wrapper, bookingsStore } = await mountDashboard()

    expect(bookingsStore.loadBookings).toHaveBeenCalledTimes(1)
    const rows = wrapper.findAll('.booking-list li')
    expect(rows).toHaveLength(2)
    expect(rows[0].text()).toContain('Polen Room')
    expect(rows[0].text()).toContain('3 Nov 2026')
    expect(rows[0].get('.badge').text()).toBe('Confirmed')
    expect(wrapper.text()).not.toContain('Marta Vidal')
  })

  it('cancels a booking after confirmation', async () => {
    vi.spyOn(window, 'confirm').mockReturnValue(true)
    const { wrapper, bookingsStore } = await mountDashboard()

    await wrapper.get('.booking-list li button').trigger('click')

    expect(window.confirm).toHaveBeenCalledWith('Cancel the booking for the Polen Room on Tuesday 3 November?')
    expect(bookingsStore.cancelBooking).toHaveBeenCalledWith('r-demo-1')
  })

  it('cancels nothing if the member changes their mind', async () => {
    vi.spyOn(window, 'confirm').mockReturnValue(false)
    const { wrapper, bookingsStore } = await mountDashboard()

    await wrapper.get('.booking-list li button').trigger('click')

    expect(bookingsStore.cancelBooking).not.toHaveBeenCalled()
  })

  it('shows a notice if the cancellation fails', async () => {
    vi.spyOn(window, 'confirm').mockReturnValue(true)
    const { wrapper, bookingsStore } = await mountDashboard()
    bookingsStore.cancelBooking.mockRejectedValue(
      errorWithStatus('Could not connect to the Colmena server', 503, 'connection')
    )

    await wrapper.get('.booking-list li button').trigger('click')
    await flushPromises()

    expect(wrapper.get('[role="alert"]').text()).toBe(
      'Could not cancel the booking on Tuesday 3 November: ' +
        'Could not connect to the Colmena server. It has been restored.'
    )
  })

  it('shows "Loading" while there are no bookings to show', async () => {
    const state = initialState()
    state.bookings = { byId: {}, ids: [], loading: true }
    const { wrapper } = await mountDashboard({ initialState: state })

    expect(wrapper.text()).toContain('Loading your bookings…')
  })

  it('reflects changes in the store and overridden getters', async () => {
    const { wrapper, bookingsStore } = await mountDashboard()

    bookingsStore.byId['r-demo-1'].status = 'cancelled'
    bookingsStore.monthlyBookingsTotal = 120 // overridden getter: only in createTestingPinia
    await flushPromises()

    expect(wrapper.findAll('.booking-list li')[0].get('.badge').text()).toBe('Cancelled')
    expect(wrapper.text()).toContain('120.00')
  })
})

Let's analyse what is new:

  • initialState() is a function, not a constant: each test receives new objects, which it can modify without affecting the others (as the "Loading" test does). The keys (session, rooms, bookings) are the stores' ids, the same ones passed to defineStore.
  • Three stores in a single initialState: the view reads useBookingsStore, myBookings queries useSessionStore and roomNameById uses useRoomsStore. With the catalogue already "loaded" (loadedAt: Date.now()), the rows show "Polen Room" instead of the id.
  • bookingsStore.loadBookings is a spy: with stubActions active, the action does nothing (there is no API request to mock), but it records the call. That is how the first test checks that the view requests the data on mounting.
  • The getters are real: myBookings really filters Laura's bookings from the initial state. That is why Marta does not appear and there are two rows, not three.
  • The cancellation is checked as an interaction: that the view asks with the right text and that it dispatches the action with the right id. What the action then does has already been tested in section 4. It is the division of responsibilities we were after: the component decides when to cancel; the store, how.
  • mockRejectedValue on an action: as the actions are vi.fn spies, they are configured like any other mock function. That way we provoke the failure without an API and check the translated notice from 07-03, with the formatted date and the reason obtained from translateError.
  • Modifying the store's state in the test (bookingsStore.byId[...].status = ...) updates the view, because it is the same reactive state. And overriding a getter (monthlyBookingsTotal = 120) is exclusive to createTestingPinia: it lets you test how a derived value is rendered without building the state that produces it.
  • afterEach with vi.restoreAllMocks() returns window.confirm to its original state.

When you run these tests you will see warnings in the console such as [intlify] Not found parent scope. use the global scope.. Vue I18n emits them in development every time <i18n-t> looks for messages of its own in the component that contains it and, not finding any, uses the global ones. It is the expected behaviour in Colmena (all the messages are global) and it appears in the same way in the application with npm run dev; it does not indicate any error in the test.

7.4 Real Pinia or createTestingPinia?

Real Pinia (createPinia) + vi.mock('@/api') createTestingPinia
Actions Real: their logic runs Spies that do nothing (unless stubActions: false)
Preparing the state Through the mocked API and the actions Directly, with initialState
Getters Real Real, and overridable as well
What it checks That view and store fit together (integration) What the component renders and which actions it dispatches
Example in Colmena RoomDetailView (08-02) DashboardBookingsView
Risk Longer tests with more mocks If the store changes its API (renames an action), the component test may keep passing with a spy that no longer corresponds to anything real

The risk in the last row is the reason for not using createTestingPinia everywhere: combine component tests with createTestingPinia and tests of the real store (this section and section 4), and let the E2E tests in the next lesson check the whole. If in some case you want the prepared states but the real actions, use createTestingPinia({ stubActions: false, ... }): the actions really run and, even so, they are spied on.

  1. Testing composables

A composable is a function that uses the Composition API to encapsulate stateful logic (01-05 anticipated it and 09-01 will develop it in depth). To test one, the key question is: does it need to be inside a component?

8.1 Composables that can be called directly

If a composable only uses ref, computed and functions, it can be called in a test like any other function. For example, the useOccupancy sketch we saw in 01-05:

// Sketch: a composable that only uses reactivity is tested like a function
it('calculates the free seats from the attendees', () => {
  const { attendees, freeSeats } = useOccupancy(8)

  expect(freeSeats.value).toBe(8)
  attendees.value = 3
  expect(freeSeats.value).toBe(5)
})

Outside a component, ref and computed work in exactly the same way. The same goes for the pure functions composables depend on, such as those in src/utils/dates.js, which you have known how to test since 08-01.

8.2 Composables that need a host component

Other composables only work inside a component's setup:

  • Those that call inject (directly or through another composable): useFormat(), useI18n(), useRoute(), useRouter(), and Pinia stores inside components.
  • Those that register lifecycle hooks (onMounted, onUnmounted): outside a component, Vue warns that there is no instance and the hook never runs.
  • Those that create watchers (watch) that must stop when the component disappears.

useFormat() is the perfect example: it injects the service that formatPlugin provides and, if it is not there, throws the error we wrote in 07-02. To test it we need a host component: a minimal component that calls the composable in its setup, mounted in an application with the necessary plugins. Create a third helper, tests/withHost.js:

// tests/withHost.js
// Runs a composable inside the setup of a minimal component, in a test application
// with the given plugins. Returns what the composable returns, and the wrapper.
import { defineComponent, h } from 'vue'
import { mount } from '@vue/test-utils'

export function withHost(composable, { plugins = [] } = {}) {
  let result

  const Host = defineComponent({
    setup() {
      result = composable()  // in here, inject and hooks work
      return () => h('div')  // renders nothing of interest
    }
  })

  const wrapper = mount(Host, { global: { plugins } })
  return { result, wrapper }
}
  • composable is a function the host calls inside setup. It can be the composable as it is (withHost(useFormat, ...)) or an arrow function that passes it arguments (withHost(() => useSomething(8), ...)).
  • result is captured in an outer variable during setup, which mount runs synchronously: by the time mount finishes, it already has a value.
  • plugins are passed to the test application as in global.plugins: here we deliberately do not use mountWithPlugins, so that each test declares exactly what the composable needs (and so that we can test what happens when something is missing).
  • wrapper is returned so that the host can be unmounted (wrapper.unmount()), and in that way we can check what the composable does in onUnmounted.

With it, the useFormat tests, in src/plugins/__tests__/useFormat.spec.js:

// src/plugins/__tests__/useFormat.spec.js
import { describe, it, expect } from 'vitest'
import { withHost } from '@tests/withHost.js'
import { formatPlugin, useFormat } from '@/plugins/format.js'

describe('useFormat', () => {
  it('returns the service of the application that installed the plugin', () => {
    const { result: format } = withHost(useFormat, {
      plugins: [[formatPlugin, { locale: 'en-GB' }]]
    })

    expect(format.locale).toBe('en-GB')
    expect(format.price(25)).toBe('€25.00')
  })

  it('gives each application its own service', () => {
    const { result: british } = withHost(useFormat, { plugins: [[formatPlugin, { locale: 'en-GB' }]] })
    const { result: spanish } = withHost(useFormat, { plugins: [[formatPlugin, { locale: 'es-ES' }]] })

    expect(british.price(25)).toBe('€25.00')
    expect(spanish.price(25)).toBe('25,00 €')
  })

  it('fails with a clear message if the application does not have the plugin', () => {
    expect(() => withHost(useFormat)).toThrow(/formatPlugin/)
  })

  it('fails with a clear message if it is called outside a component', () => {
    expect(() => useFormat()).toThrow('useFormat() must be called')
  })
})
  • The second test checks the per-application isolation from 07-02: two applications, two services, without the second overwriting the first. It is the test that would have caught the formatPluginBad with module state that we analysed there.
  • The third mounts a host without the plugin: the error that useFormat() throws inside setup makes the mount fail, and toThrow catches it. When you run it you will see a Vue warning in the console ("Component is missing template or render function"): setup never got to return the render function because it was interrupted by the error, which is exactly what we are checking.
  • The fourth does not need a host: it checks precisely what happens without one. hasInjectionContext() returns false and the composable throws its message.

withHost will be the tool for testing the composables Colmena will have in the next module: when in 09-01 you extract the repeated logic for filters, availability and requests into composables (useRoomFilters, useAvailability, useRequest), those that use inject, the router, a store or lifecycle hooks will be tested in exactly this way.

  1. Which strategy to use for each piece

With the three lessons on unit and integration testing finished, this is the complete map:

Piece Example in Colmena Strategy Tools
Pure function createFormat, dates.js Call it and check the result expect
Composable that only uses reactivity The useOccupancy sketch Call it directly ref/computed and .value
Composable with inject, lifecycle or watchers useFormat Host component with the necessary plugins withHost
Presentational component StatusBadge, RoomCard, TextField, BaseButton Mount it with props, slots and events mountWithPlugins, trigger, emitted
Component with timers ReceptionClock Fake timers vi.useFakeTimers, setSystemTime
A store's logic useRoomsStore, useBookingsStore, useSessionStore Real store, new Pinia, mocked API setActivePinia(createPinia()), vi.mock('@/api'), $patch
Pinia plugin persistence Pinia installed in an empty application, jsdom's storage createApp({}).use(pinia)
View with a store, integration RoomDetailView, LoginView Real view and store, mocked API, in-memory router createPinia(), createTestRouter
View with a store, the component DashboardBookingsView Prepared state and spied actions createTestingPinia
The user's complete flow Signing in, booking, cancelling E2E test in a real browser Cypress (08-04)

  1. Try it

  1. All green. Run npm test: the files for the three stores, persistence, DashboardBookingsView and useFormat are added.
  2. The rollback. In src/stores/bookings.js, comment out the rollback line (byId.value[id].status = previousStatus). Only the test "cancels instantly and rolls back if the API fails" fails, and its message says exactly what it expected: 'confirmed'. Restore it.
  3. The cache limit. In src/stores/rooms.js, change the < in the freshness check to <=. The five-minute test fails: with exactly 5 minutes, the copy would still be considered fresh. Restore it.
  4. The persisted contract. In useSessionStore, change the key to 'colmena-session-v2': the persistence test fails and reminds you that this key is a contract with sessions that are already open. Restore it.
  5. No application. In persistence.spec.js, comment out the createApp({}).use(pinia) line in the helper: all the tests fail, because the plugin never gets applied. Restore it.
  6. Each test watches over its own part. In DashboardBookingsView.vue, temporarily change bookingsStore.cancelBooking(booking.id) to bookingsStore.cancelBooking(booking.roomId). The store tests stay green (the store has not changed) and the view's test fails, as it expected 'r-demo-1' and received 'polen'. Now undo that change and, in the store, comment out the booking.status = 'cancelled' line in cancelBooking: the store test fails and the view's test stays green, because with createTestingPinia the action is a spy. Each level detects the bugs within its own responsibility. Restore everything.

Common Mistakes and Tips

  • Calling useXStore() without an active Pinia. The error getActivePinia() was called but there was no active Pinia indicates that setActivePinia(createPinia()) is missing from the beforeEach (or the plugin from the mount).
  • Sharing the Pinia between tests. State and caches carry over from one test to another. A new Pinia in every beforeEach or on every mount.
  • Testing the Pinia plugin without an application. Pinia does not apply plugins until the instance is installed with app.use(pinia).
  • Forgetting to empty localStorage and sessionStorage. jsdom keeps them between tests in the same file: clear() in beforeEach.
  • Using mockResolvedValue with an object the store modifies. Every call would receive the same object. Return copies with mockImplementation(async () => structuredClone(...)).
  • Building the normalised state by hand in every test. Encapsulate it in a helper (withBookings) so that the internal structure lives in a single place.
  • Using createTestingPinia to test the store's logic. Its actions do nothing: you would be testing a spy. The logic, with the real store.
  • Forgetting createSpy: vi.fn when using createTestingPinia without Vitest's globals: it would not know how to create the spies.
  • Calling a composable with inject or hooks outside a component. Use withHost.
  • Tip: when a bug reaches production, first write the store test that reproduces it. Stores concentrate the business rules, and a broken rule can usually be reproduced in three lines of test.

Exercises

Exercise 1. Write tests for the monthlyBookingsTotal getter of useBookingsStore, which adds up the price of the active bookings in myBookings for the current month according to each room's hourlyPrice. Set the current date to 10 November 2026, load the catalogue into useRoomsStore with $patch, and prepare these bookings: Laura in the Polen Room on 3 November from 10:00 to 12:00 (confirmed); Laura in the Néctar Room on 20 November from 9:00 to 13:00 (confirmed); Laura in the Panal Room on 5 November (cancelled); Laura in the Panal Room on 1 December; Marta in the Néctar Room on 3 November from 16:00 to 17:00. Work out by hand the expected amount for Laura (member) and for Marta (manager) and check it.

Exercise 2. DashboardBookingsView has the "Hide cancelled bookings" checkbox from 06-01. With createTestingPinia, check that: (a) when it is ticked, the cancelled booking disappears from the list; (b) if all of the member's bookings are cancelled and the checkbox is ticked, "All your bookings are cancelled." appears and there is no list.

Exercise 3. In 07-03 we connected formatPlugin to the language with { locale: localeIntl }, and we warned that writing localeIntl() would freeze the formats. Write two tests with withHost that prove it: with i18n and formatPlugin installed, the first must check that, when i18n.global.locale.value changes to 'es', useFormat() starts formatting 25 as 25,00 € (with the non-breaking space); the second, that with localeIntl() (with parentheses) the price stays in the British format. Make sure you set the language back to 'en' after each test.

Solutions

Solution 1. For Laura (member): Polen, 2 hrs × €15 = €30; Néctar, 4 hrs × €35 = €140; the cancelled one and the December one do not count; Marta's is not hers. Total: €170. For Marta (a manager, who sees them all): €170 + 1 hr × €35 = €205.

// src/stores/__tests__/monthlyTotal.spec.js
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'
import { rooms } from '@/data/rooms.js'
import { useBookingsStore } from '@/stores/bookings.js'
import { useRoomsStore } from '@/stores/rooms.js'
import { useSessionStore } from '@/stores/session.js'

vi.mock('@/api')

function createTestBooking(changes = {}) {
  return {
    id: 'r-1', roomId: 'polen', date: '2026-11-03', startTime: '10:00', endTime: '12:00',
    member: 'Laura Gómez', attendees: 3, status: 'confirmed', extraEquipment: [], notes: '',
    ...changes
  }
}

describe('monthlyBookingsTotal', () => {
  beforeEach(() => {
    setActivePinia(createPinia())
    vi.useFakeTimers()
    vi.setSystemTime(new Date(2026, 10, 10, 12, 0)) // current month: November 2026

    useRoomsStore().$patch({ rooms: structuredClone(rooms), loadedAt: Date.now() })

    const list = [
      createTestBooking({ id: 'a' }),
      createTestBooking({ id: 'b', roomId: 'nectar', date: '2026-11-20', startTime: '09:00', endTime: '13:00' }),
      createTestBooking({ id: 'c', roomId: 'panal', date: '2026-11-05', status: 'cancelled' }),
      createTestBooking({ id: 'd', roomId: 'panal', date: '2026-12-01' }),
      createTestBooking({ id: 'e', roomId: 'nectar', member: 'Marta Vidal', startTime: '16:00', endTime: '17:00' })
    ]
    useBookingsStore().$patch({
      byId: Object.fromEntries(list.map((b) => [b.id, b])),
      ids: list.map((b) => b.id)
    })
  })

  afterEach(() => {
    vi.useRealTimers()
  })

  it('adds up the member’s active bookings for the month', () => {
    useSessionStore().$patch({ name: 'Laura Gómez', email: '[email protected]', role: 'member' })

    expect(useBookingsStore().monthlyBookingsTotal).toBe(170)
  })

  it('adds up those of the whole centre for a manager', () => {
    useSessionStore().$patch({ name: 'Marta Vidal', email: '[email protected]', role: 'manager' })

    expect(useBookingsStore().monthlyBookingsTotal).toBe(205)
  })
})
  • vi.setSystemTime sets the "current month" that currentMonth() calculates. Without it, the test would depend on the real date and would stop passing in December.
  • Each excluded booking is excluded for a different reason (cancelled, another month, another member): if any rule breaks, the total changes and the test catches it. Working out the expected result by hand, and not copying it from a run, is what gives the test its value.

Solution 2.

// In DashboardBookingsView.spec.js: a helper for mounting with a specific list
async function mountWithList(list) {
  const state = initialState()
  state.bookings = { byId: Object.fromEntries(list.map((b) => [b.id, b])), ids: list.map((b) => b.id) }
  return mountDashboard({ initialState: state })
}

it('hides the cancelled bookings when the checkbox is ticked', async () => {
  const { wrapper } = await mountWithList([
    createTestBooking({ id: 'a' }),
    createTestBooking({ id: 'b', date: '2026-11-04', status: 'cancelled' })
  ])
  expect(wrapper.findAll('.booking-list li')).toHaveLength(2)

  await wrapper.get('input[type="checkbox"]').setValue(true)

  const rows = wrapper.findAll('.booking-list li')
  expect(rows).toHaveLength(1)
  expect(rows[0].get('.badge').text()).toBe('Confirmed')
})

it('explains that they are all cancelled if none is left visible', async () => {
  const { wrapper } = await mountWithList([createTestBooking({ id: 'b', status: 'cancelled' })])

  await wrapper.get('input[type="checkbox"]').setValue(true)

  expect(wrapper.text()).toContain('All your bookings are cancelled.')
  expect(wrapper.find('.booking-list').exists()).toBe(false)
})

setValue(true) on a checkbox ticks it and triggers change, the event v-model listens to on a checkbox. The second case checks the v-else-if branch that distinguishes "you have no bookings" from "you have hidden them all": two different messages for two different situations, as we decided in 06-01.

Solution 3.

// src/plugins/__tests__/formatLanguage.spec.js
import { describe, it, expect, afterEach } from 'vitest'
import { withHost } from '@tests/withHost.js'
import { i18n, localeIntl } from '@/i18n.js'
import { formatPlugin, useFormat } from '@/plugins/format.js'

describe('formatPlugin connected to the language', () => {
  afterEach(() => {
    i18n.global.locale.value = 'en' // the application's i18n is shared: we leave it as it was
  })

  it('follows the active language if it receives the localeIntl function', () => {
    const { result: format } = withHost(useFormat, {
      plugins: [i18n, [formatPlugin, { locale: localeIntl, currency: 'EUR' }]]
    })
    expect(format.price(25)).toBe('€25.00')

    i18n.global.locale.value = 'es'

    expect(format.locale).toBe('es-ES')
    expect(format.price(25)).toBe('25,00 €')
  })

  it('stays in the start-up language if it receives localeIntl()', () => {
    const { result: format } = withHost(useFormat, {
      plugins: [i18n, [formatPlugin, { locale: localeIntl(), currency: 'EUR' }]]
    })

    i18n.global.locale.value = 'es'

    expect(format.price(25)).toBe('€25.00')
  })
})
  • We change the language by assigning i18n.global.locale.value and not with changeLanguage, because we are only interested in the Intl locale: changeLanguage would download the messages and touch <html lang> and localStorage, effects this test does not need.
  • The afterEach is essential: i18n is a single object shared by all the tests that use mountWithPlugins. If a test left it in Spanish, the RoomCard tests would start seeing "15,00 €" instead of "€15.00" and would fail for no apparent reason. It is the same shared-state problem we solved with createPinia() in each test, in another place.
  • The second test pins down the mistake we described in 07-03: localeIntl() is evaluated once, the plugin receives the string 'en-GB' and there is no longer anything that follows the language.

Conclusion

Pinia stores are logic without an interface and they are tested directly: a setActivePinia(createPinia()) in each beforeEach gives each test new stores, vi.mock('@/api') isolates them from the API, $patch prepares the starting state, and the assertions go through state, getters and actions. That is how we have pinned down Colmena's most delicate rules: the five-minute cache and the deduplication in loadRooms (with fake timers), the booking with the server's id and the rejection for overlaps in createBooking, the optimistic cancellation with rollback (with a controlled promise to observe the intermediate state), the myBookings filter according to the role, and signing in and out, which empties the bookings. The persistence plugin is tested with a Pinia installed in an empty application and jsdom's storage, emptied before each test. For components that read stores, createTestingPinia from @pinia/testing offers a made-to-measure initial state (initialState), actions turned into spies (stubActions, createSpy: vi.fn) and overridable getters, which has let us test DashboardBookingsView without an API. And composables are tested directly if they only use reactivity, or inside a host component with withHost(composable, { plugins }) from tests/withHost.js if they use inject, hooks or watchers, like useFormat.

Colmena now has unit and integration tests for its functions, components, views, stores, plugins and composables, which run in seconds. But they all share a limitation: they run in jsdom, with pieces mounted separately, a test router and a made-to-measure mocked API. None of them has checked that the complete application works in a real browser, with its main.js, its real navigation guards, its lazy loading of views and languages and its real storage; in other words, that a member can sign in, find a room, book it and cancel it. That is what end-to-end tests do, and we will write them in End-to-End Testing with Cypress.

New edition · October 2026

Vue.js Course

Module 1: Introduction to Vue.js

Module 2: Vue.js Basics

Module 3: Vue.js Components

Module 4: Vue Router

Module 5: State Management with Vuex and Pinia

Module 6: Vue.js Directives

Module 7: Vue.js Plugins

Module 8: Testing in Vue.js

Module 9: Advanced Vue.js Concepts

Module 10: Building and Deploying Vue.js Applications

Module 11: Real-World Vue.js Projects

© Copyright 2026. All rights reserved