all files / src/__tests__/ bindActionData.spec.js

100% Statements 38/38
100% Branches 4/4
82.35% Functions 14/17
100% Lines 24/24
3 statements Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77                                                                                                           
import expect from 'expect'
import bindActionData from '../bindActionData'
 
describe('bindActionData', () => {
  it('should return a function when called with a function', () => {
    expect(bindActionData(() => ({ foo: 'bar' }), { baz: 7 }))
      .toExist()
      .toBeA('function')
  })
 
 
  it('should add keys when called with a function', () => {
    expect(bindActionData(() => ({ foo: 'bar' }), { baz: 7 })())
      .toEqual({
        foo: 'bar',
        baz: 7
      })
  })
 
  it('should pass along arguments when called with a function', () => {
    const action = bindActionData(data => ({ foo: data }), { baz: 7 })
    expect(action('dog'))
      .toEqual({
        foo: 'dog',
        baz: 7
      })
    expect(action('cat'))
      .toEqual({
        foo: 'cat',
        baz: 7
      })
  })
 
  it('should return an object when called with an object', () => {
    const actions = bindActionData({
      a: () => ({ foo: 'bar' }),
      b: () => ({ cat: 'ralph' })
    }, { baz: 7 })
    expect(actions).toExist().toBeA('object')
    expect(Object.keys(actions).length).toBe(2)
    expect(actions.a).toExist().toBeA('function')
    expect(actions.b).toExist().toBeA('function')
  })
 
  it('should add keys when called with an object', () => {
    const actions = bindActionData({
      a: () => ({ foo: 'bar' }),
      b: () => ({ cat: 'ralph' })
    }, { baz: 7 })
    expect(actions.a()).toEqual({
      foo: 'bar',
      baz: 7
    })
    expect(actions.b()).toEqual({
      cat: 'ralph',
      baz: 7
    })
  })
 
  it('should pass along arguments when called with an object', () => {
    const actions = bindActionData({
      a: value => ({ foo: value }),
      b: value => ({ cat: value })
    }, { baz: 9 })
    expect(actions.a('dog'))
      .toEqual({
        foo: 'dog',
        baz: 9
      })
    expect(actions.b('Bob'))
      .toEqual({
        cat: 'Bob',
        baz: 9
      })
  })
})