@guj/rif-js
Version:
Simplify filter,map and such when their use should be conditionnal
33 lines (27 loc) • 942 B
JavaScript
const test = require("ava");
const Rif = require("../main/rif");
test('Rif should be considered arrays', t => {
const rSut = Rif.of([1]);
t.deepEqual(rSut, [1], `The first element of this Rif is 1`);
});
test('Rif methods should return Rifs to be chainable', t => {
const rSut = Rif
.of([1])
.mapIf(true)(x=>x+1)
.mapIf(true)(x=>x*2);
t.deepEqual(rSut, [4], `The first element has been mapped twice`);
});
test('Muted Rif methods should return Rifs to be chainable', t => {
const rSut = Rif
.of([1])
.mapIf(false)(x=>x+1)
.mapIf(false)(x=>x*2);
t.deepEqual(rSut, [1], `The first element has not been mapped at all`);
});
test('Array methods called on a Rif should return Rifs to be chainable', t => {
const rSut = Rif
.of([1])
.map(x=>x+1)
.mapIf(true)(x=>x*2);
t.deepEqual(rSut, [4], `The first element has been mapped twice`);
});