Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
TASK: Change the specification of
Browse files Browse the repository at this point in the history
  • Loading branch information
grebaldi committed Feb 17, 2016
1 parent 97dcbcc commit 4f1fb2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
5 changes: 1 addition & 4 deletions src/projections/atoms/and/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
const reduceOps = ops => subject => ops.reduce(
(subject, nextOp) => subject === false ? subject : nextOp(subject),
subject
);
const reduceOps = ops => subject => ops.every(op => op(subject));

//
// Performs all passed operations until one of them returns false
Expand Down
34 changes: 14 additions & 20 deletions src/projections/atoms/and/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ describe('Connections > Atoms > $and', () => {
});

describe('Vanilla JS', () => {
it('should call all passed functions with the passed subject', () => {
it('should call all passed functions with the passed subject and return true, if all them return truthy values', () => {
const subject = 'mySubject';
const op1 = sinon.spy(id);
const op2 = sinon.spy(id);
const op3 = sinon.spy(id);

expect($and(op1, op2, op3, subject)).to.equal('mySubject');
expect($and(op1, op2, op3, subject)).to.equal(true);
expect(op1.called).to.equal(true);
expect(op1.getCall(0).args[0]).to.equal('mySubject');
expect(op2.called).to.equal(true);
Expand All @@ -42,33 +42,27 @@ describe('Connections > Atoms > $and', () => {
expect(op3.getCall(0).args[0]).to.equal('mySubject');
});

it('should call the passed functions in a predictable order', () => {
const subject = 1;
const op1 = sinon.spy(a => a + 1);
const op2 = sinon.spy(a => a + 2);
const op3 = sinon.spy(a => a + 3);

expect($and(op1, op2, op3, subject)).to.equal(7);
expect($and(op3, op2, op1, subject)).to.equal(7);

expect(op1.getCall(0).args[0]).to.equal(1);
expect(op1.getCall(1).args[0]).to.equal(6);
expect(op2.getCall(0).args[0]).to.equal(2);
expect(op2.getCall(1).args[0]).to.equal(4);
expect(op3.getCall(0).args[0]).to.equal(4);
expect(op3.getCall(1).args[0]).to.equal(1);
});

it('should return false, if any of the functions returns false', () => {
it('should return false, if any of the functions returns a falsy value', () => {
const subject = 'mySubject';
const opTrue = () => true;
const opFalse = () => false;
const opFalsy1 = () => '';
const opFalsy2 = () => null;
const opFalsy3 = () => undefined;
const opFalsy4 = () => NaN;
const opFalsy5 = () => 0;

expect($and(opTrue, opTrue, opTrue, opTrue, subject)).to.equal(true);
expect($and(opFalse, opTrue, opTrue, opTrue, subject)).to.equal(false);
expect($and(opTrue, opFalse, opTrue, opTrue, subject)).to.equal(false);
expect($and(opTrue, opTrue, opFalse, opTrue, subject)).to.equal(false);
expect($and(opTrue, opTrue, opTrue, opFalse, subject)).to.equal(false);

expect($and(opTrue, opTrue, opFalsy1, opTrue, subject)).to.equal(false);
expect($and(opTrue, opTrue, opFalsy2, opTrue, subject)).to.equal(false);
expect($and(opTrue, opTrue, opFalsy3, opTrue, subject)).to.equal(false);
expect($and(opTrue, opTrue, opFalsy4, opTrue, subject)).to.equal(false);
expect($and(opTrue, opTrue, opFalsy5, opTrue, subject)).to.equal(false);
});
});
});

0 comments on commit 4f1fb2e

Please sign in to comment.