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

84.62% Statements 22/26
100% Branches 4/4
66.67% Functions 8/12
82.61% Lines 19/23
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                                          
import expect from 'expect';
import isEvent from '../isEvent';
 
describe('isEvent', () => {
  it('should return false if event is undefined', () => {
    expect(isEvent()).toBe(false);
  });
 
  it('should return false if event is null', () => {
    expect(isEvent(null)).toBe(false);
  });
 
  it('should return false if event is not an object', () => {
    expect(isEvent(42)).toBe(false);
    expect(isEvent(true)).toBe(false);
    expect(isEvent(false)).toBe(false);
    expect(isEvent('not an event')).toBe(false);
  });
 
  it('should return false if event has no stopPropagation', () => {
    expect(isEvent({
      preventDefault: () => null
    })).toBe(false);
  });
 
  it('should return false if event has no preventDefault', () => {
    expect(isEvent({
      stopPropagation: () => null
    })).toBe(false);
  });
 
  it('should return true if event has stopPropagation, and preventDefault', () => {
    expect(isEvent({
      stopPropagation: () => null,
      preventDefault: () => null
    })).toBe(true);
  });
});