OVERMIND
v26
v26
  • Overmind
  • Introduction
  • Quickstart
  • How to learn
  • Videos
  • FAQ
  • Core
    • Devtools
    • Configuration
    • State
    • Actions
    • Effects
    • Operators
    • Server Side Rendering
    • Typescript
  • views
    • React
    • Angular
    • Vue
    • Svelte
  • Addons
    • GraphQL
    • Statechart
  • Guides
    • Using state machines
    • Connecting components
    • Managing lists
    • State first routing
    • Move to Typescript
    • Testing
    • Connecting to React Native
  • API
    • action
    • addFlushListener
    • addMutationListener
    • createOvermind
    • createOvermindMock
    • createOvermindSSR
    • derived
    • effects
    • events
    • json
    • lazy
    • merge
    • namespaced
    • onInitialize
    • operators
    • reaction
    • rehydrate
    • statemachine
Powered by GitBook
On this page
  1. API

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()
    })
  })
})

It is important that you separate your config from the instantiation of Overmind, meaning that createOvermind should not be used in the same file as the config you see imported here, it should rather be used where you render your application. This allows the config to be used for multiple purposes.

PreviouscreateOvermindNextcreateOvermindSSR

Last updated 4 years ago