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

92% Statements 23/25
100% Branches 4/4
75% Functions 6/8
90.91% Lines 20/22
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                                                  
import expect, {createSpy} from 'expect';
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('foo', blur)('bar');
    expect(blur)
      .toHaveBeenCalled()
      .toHaveBeenCalledWith('foo', 'bar');
  });
 
  it('should return a function that calls blur with name and value from event', () => {
    const blur = createSpy();
    createOnBlur('foo', blur)({
      target: {
        value: 'bar'
      },
      preventDefault: () => null,
      stopPropagation: () => null
    });
    expect(blur)
      .toHaveBeenCalled()
      .toHaveBeenCalledWith('foo', 'bar');
  });
 
  it('should return a function that calls blur and then afterBlur with name and value', () => {
    const blur = createSpy();
    const afterBlur = createSpy();
    createOnBlur('foo', blur, false, afterBlur)('bar');
    expect(blur).toHaveBeenCalled();
    expect(afterBlur)
      .toHaveBeenCalled()
      .toHaveBeenCalledWith('foo', 'bar');
  });
 
});