Skip to content

Instantly share code, notes, and snippets.

@iamwill123
Last active July 3, 2021 15:53
Show Gist options
  • Save iamwill123/bebf4708c1db748ecdd04b1c5512084f to your computer and use it in GitHub Desktop.
Save iamwill123/bebf4708c1db748ecdd04b1c5512084f to your computer and use it in GitHub Desktop.
*WIP* isReallyEmpty - Ramda - enzyme / jest test
import { all, either, is, isEmpty, isNil, pipe, values,when } from 'ramda'
const isNilOrEmpty = either(isNil, isEmpty)
const areAllNilOrEmpty = pipe(
when(is(Object), values),
all(isNilOrEmpty),
)
describe('nilOrEmptyCheck util contains two utils, returns boolean (true or false)', () => {
let result, value, string, arr, obj, stringRes, arrRes, objResult
describe('isNilOrEmpty', () => {
it('should return true if value is null', () => {
value = null
result = isNilOrEmpty(value)
expect(result).toBe(true)
})
it('should return true if value is undefined', () => {
value = undefined
result = isNilOrEmpty(value)
expect(result).toBe(true)
})
})
describe('areAllNilOrEmpty', () => {
it('should return true if value is an empty ', () => {
value = ''
result = areAllNilOrEmpty(value)
expect(result).toBe(true)
})
it('should return true if value is an empty string, [], {}', () => {
string = ''
arr = []
obj = {}
stringRes = areAllNilOrEmpty(string)
arrRes = areAllNilOrEmpty(arr)
objResult = areAllNilOrEmpty(obj)
expect(stringRes).toBe(true)
expect(arrRes).toBe(true)
expect(objResult).toBe(true)
})
it('should return true if nest objects contain empty, undefined or null values', () => {
arr = ['', null]
obj = {x: '', y: null, z: undefined}
arrRes = areAllNilOrEmpty(arr)
objResult = areAllNilOrEmpty(obj)
expect(arrRes).toBe(true)
expect(objResult).toBe(true)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment