all files / src/events/__tests__/ createOnBlur.spec.js

100% Statements 25/25
100% Branches 4/4
100% Functions 6/6
100% Lines 18/18
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                                                       
import expect, {createSpy} from 'expect'
import noop from 'lodash.noop'
import createOnBlur from '../createOnBlur'
 
describe('createOnBlur', () => {
  it('should return a function', () => {
    expect(createOnBlur())
      .toExist()
      .toBeA('function')
  })
 
  it('should return a function that calls blur with name and value', () => {
    const blur = createSpy()
    createOnBlur(blur)('bar')
    expect(blur)
      .toHaveBeenCalled()
      .toHaveBeenCalledWith('bar')
  })
 
  it('should return a function that calls blur with name and value from event', () => {
    const blur = createSpy()
    createOnBlur(blur)({
      target: {
        value: 'bar'
      },
      preventDefault: noop,
      stopPropagation: noop
    })
    expect(blur)
      .toHaveBeenCalled()
      .toHaveBeenCalledWith('bar')
  })
 
  it('should return a function that calls blur and then afterBlur with name and value', () => {
    const blur = createSpy()
    const afterBlur = createSpy()
    createOnBlur(blur, afterBlur)('bar')
    expect(blur).toHaveBeenCalled()
    expect(afterBlur)
      .toHaveBeenCalled()
      .toHaveBeenCalledWith('bar')
  })
 
})