Skip to main content
Module

x/rambda/source/reduce.spec.js

Faster and smaller alternative to Ramda
Go to Latest
File
import {reduce} from './reduce'
const reducer = (prev, current, i) => { expect(i).toBeNumber()
return prev + current}const initialValue = 1const list = [1, 2, 3]const ERROR = 'reduce: list must be array or iterable'
test('happy', () => { expect(reduce(reducer, initialValue, list)).toEqual(7)})
test('with object as iterable', () => { expect(() => reduce(reducer, initialValue, { a: 1, b: 2, }) ).toThrowWithMessage(TypeError, ERROR)})
test('with undefined as iterable', () => { expect(() => reduce(reducer, 0, null)).toThrowWithMessage(TypeError, ERROR)})