all files / src/structure/plain/__tests__/ getIn.spec.js

100% Statements 17/17
100% Branches 4/4
100% Functions 5/5
100% Lines 12/12
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                                   
import expect from 'expect'
import getIn from '../getIn'
 
describe('structure.plain.getIn', () => {
  it('should return undefined if state is undefined', () => {
    expect(getIn(undefined, 'dog')).toBe(undefined)
  })
 
  it('should get shallow values', () => {
    expect(getIn({ foo: 'bar' }, 'foo')).toBe('bar')
    expect(getIn({ foo: 42 }, 'foo')).toBe(42)
    expect(getIn({ foo: false }, 'foo')).toBe(false)
  })
 
  it('should get deep values', () => {
    const state = {
      foo: {
        bar: [
          'baz',
          { dog: 42 }
        ]
      }
    }
    expect(getIn(state, 'foo.bar[0]')).toBe('baz')
    expect(getIn(state, 'foo.bar[1].dog')).toBe(42)
  })
})