Skip to content

Commit

Permalink
Get coverage up
Browse files Browse the repository at this point in the history
  • Loading branch information
Einar Norðfjörð committed Jan 28, 2018
1 parent 5031e34 commit 9a7bc8c
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 70 deletions.
11 changes: 3 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,6 @@ flyd.fromPromise = function(promise) {
promise.then(function onSuccess(val) {
s(val);
s.end(true);
}, function onError(err) {
s.end(true);
throw err;
});
return s;
}
Expand Down Expand Up @@ -417,11 +414,8 @@ function boundAp(s2) {
/**
* @private
*/
function fantasy_land_ap(s2) {
var s1 = this;
return combine(function(s1, s2, self) {
self(s2.val(s1.val));
}, [s1, s2]);
function fantasy_land_ap(s1) {
return ap(this, s1);
}

/**
Expand Down Expand Up @@ -614,6 +608,7 @@ function flushUpdate() {
* @param {*} value
*/
function updateStreamValue(s, n) {
/* istanbul ignore if */
if (n !== undefined && n !== null && isFunction(n.then)) {
console.warn('Promise swallowing has been deprecated in favour of flyd.fromPromise');
n.then(s);
Expand Down
61 changes: 0 additions & 61 deletions module/flatmap/test/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"fantasy-land": "^3.5.0",
"ramda": "^0.19.1"
"ramda": "^0.25.0"
},
"devDependencies": {
"benchmark": "^1.0.0",
Expand Down
96 changes: 96 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,63 @@ describe('stream', function() {
});
});

describe('chain', function() {
it('applies function to values in stream', function() {
var result = [];
function f(v) {
result.push(v);
return stream();
}
var s = stream();
flyd.chain(f, s);
s(1)(2)(3)(4)(5);
assert.deepEqual(result, [1, 2, 3, 4, 5]);
});
it('returns stream with result from all streams created by function', function() {
var result = [];
function f(v) {
var s = stream();
setImmediate(function() {
s(v + 1)(v + 2)(v + 3);
});
return s;
}
var s = stream();
flyd.map(function(v) {
result.push(v);
}, flyd.chain(f, s));
s(1)(3)(5);
setImmediate(function() {
assert.deepEqual(result, [2, 3, 4,
4, 5, 6,
6, 7, 8]);
});
});
it('passed bug outlined in https://github.com/paldepind/flyd/issues/31', function(done) {
function delay(val, ms) {
var outStream = flyd.stream();

setTimeout(function() {
outStream(val);
outStream.end(true);
}, ms);

return outStream;
}

var main = delay(1, 500);
var merged = flyd.chain(function(v) {
return delay(v, 1000)
}, main);

flyd.on(function() {
assert(main() === 1);
assert(merged() === 1);
done();
}, merged.end);
});
});

describe('scan', function() {
it('has initial acc as value when stream is undefined', function() {
var numbers = stream();
Expand Down Expand Up @@ -839,4 +896,43 @@ describe('stream', function() {
]);
});
});

describe('fantasy-land', function() {
it('map', function() {
var s = stream(1);
var mapped = R.map(R.add(3), s);
assert.equal(mapped(), 4);
assert.equal(s(), 1);
});

it('chain', function() {
var s = stream(1);
var chained = R.chain(R.compose(stream, R.add(3)), s);
assert.equal(chained(), 4);
assert.equal(s(), 1);
});

it('ap', function() {
var s = stream(R.add(3));
var val = stream(3);
var applied = R.ap(s, val);
assert.equal(applied(), 6);
});

it('old ap', function() {
var s = stream(R.add(3))
.ap(stream(3));
assert.equal(s(), 6);
});

it('of', function() {
var s = flyd.of(3);
var s2 = s['fantasy-land/of'](5);
assert(flyd.isStream(s));
assert.equal(s(), 3);

assert(flyd.isStream(s2));
assert.equal(s2(), 5);
})
});
});

0 comments on commit 9a7bc8c

Please sign in to comment.