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

100% Statements 29/29
100% Branches 4/4
100% Functions 10/10
100% Lines 26/26
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 from 'expect';
import isValid from '../isValid';
 
describe('isValid', () => {
 
  it('should return true if the value is falsy', () => {
    expect(isValid(undefined)).toBe(true);
    expect(isValid(null)).toBe(true);
    expect(isValid(false)).toBe(true);
  });
 
  it('should return false if the value is truthy', () => {
    expect(isValid('error')).toBe(false);
    expect(isValid(true)).toBe(false);
  });
 
  it('should return true if the value is an array of falsy values', () => {
    expect(isValid([undefined, null, false])).toBe(true);
  });
 
  it('should return true if the value is an empty array', () => {
    expect(isValid([])).toBe(true);
  });
 
  it('should return false if the value is an array with one truthy value', () => {
    expect(isValid([undefined, 'error', undefined])).toBe(false);
  });
 
  it('should return true if the value is an empty object', () => {
    expect(isValid({})).toBe(true);
  });
 
  it('should return true if the value is an object with a falsy value', () => {
    expect(isValid({name: undefined})).toBe(true);
    expect(isValid({name: null})).toBe(true);
    expect(isValid({name: false})).toBe(true);
    expect(isValid({name: ''})).toBe(true);
  });
 
  it('should return false if the value is an object with a value', () => {
    expect(isValid({name: 'error'})).toBe(false);
  });
});