Skip to main content
Module

x/rambda/map.spec.js

Faster and smaller alternative to Ramda
Go to Latest
File
import { map } from './map'
const double = x => x * 2
const sampleObject = { a : 1, b : 2, c : 3, d : 4,}
test('with array', () => { expect(map(double, [ 1, 2, 3 ])).toEqual([ 2, 4, 6 ])})
test('with object', () => { const obj = { a : 1, b : 2, }
expect(map(double, obj)).toEqual({ a : 2, b : 4, })})
test('pass input object as third argument', () => { const obj = { a : 1, b : 2, } const iterator = ( val, prop, inputObject ) => { expect(inputObject).toEqual(obj)
return val * 2 }
expect(map(iterator, obj)).toEqual({ a : 2, b : 4, })})
test('with object passes property as second argument', () => { map((_, prop) => { expect(typeof prop).toEqual('string') })(sampleObject)})
/** * https://github.com/selfrefactor/rambda/issues/77 */test('when undefined instead of array', () => { expect(map(double, undefined)).toEqual([])})