Redux 摩卡

Redux 非常实用,因此单元测试非常简单。

行动创造者:

export function showSidebar () {
  return {
    type: 'SHOW_SIDEBAR'
  }
}

动作创建者单元测试:

import expect from 'expect'
import actions from './actions'
import * as type from './constants'

describe('actions', () => {
  it('should show sidebar', () => {
    const expectedAction = {
      type: type.SHOW_SIDEBAR
    }
    expect(actions.showSidebar()).toEqual(expectedAction)
  })
})