createOvermindMock

The createOvermindMock factory creates an instance of Overmind which can be used to test actions. You can mock out effects and evaluate mutations performed during action execution.

import { createOvermindMock } from 'overmind'
import { config } from './'

describe('Actions', () => {
  describe('getPost', () => {
    test('should get post with passed id', async () => {
      const overmind = createOvermindMock(config, {
        api: {
          getPost(id) {
            return Promise.resolve({
              id
            })
          }
        }
      })

      await overmind.actions.getPost('1')

      expect(overmind.mutations).toMatchSnapshot()
    })
    test('should handle errors', async () => {
      const overmind = createOvermindMock(config, {
        api: {
          getPost() {
            throw new Error('test')
          }
        }
      })

      await overmind.actions.getPost('1')

      expect(overmind.mutations).toMatchSnapshot()
    })
  })
})

Setting initial state

Pass a function as the second or third argument to set initial state.

import { createOvermindMock } from 'overmind'
import { config } from './'

describe('State', () => {
  test('should derive authors of posts', async () => {
    const overmind = createOvermindMock(config, (state) => {
      state.posts = { 1: { id: 1, author: 'Janet' } }
    })

    expect(overmind.state.authors).toEqual(['Janet'])
  })
})

Last updated