Skip to content

Commit

Permalink
fix(debug): support usage with no argument given
Browse files Browse the repository at this point in the history
Debug operator should use console.log if no argument if given, but it was crashing with an error.

Closes issue #87.
  • Loading branch information
staltz committed Jul 22, 2016
1 parent 1adc780 commit 6cefc81
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"markdox": "^0.1.10",
"mkdirp": "^0.5.1",
"mocha": "^2.4.5",
"sinon": "^1.16.0",
"strip-comments": "^0.4.4",
"ts-node": "^0.9.0",
"tslint": "^3.6.0",
Expand Down
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export class DebugOperator<T> implements Operator<T, T> {
this.l = '';
if (typeof arg === 'string') {
this.l = arg;
} else {
} else if (typeof arg === 'function') {
this.s = arg;
}
}
Expand Down
33 changes: 33 additions & 0 deletions tests/operator/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
/// <reference path="../../typings/globals/node/index.d.ts" />
import xs, {Stream, MemoryStream} from '../../src/index';
import * as assert from 'assert';
import * as sinon from 'sinon';

var sandbox: sinon.SinonSandbox;
describe('Stream.prototype.debug', () => {
beforeEach(function () {
sandbox = sinon.sandbox.create();
});

afterEach(function () {
sandbox.restore();
});

it('should allow inspecting the operator chain', (done) => {
const expected = [0, 1, 2];
const stream = xs.periodic(50).take(3).debug(x => {
Expand All @@ -23,6 +33,29 @@ describe('Stream.prototype.debug', () => {
stream.addListener(listener);
});

it('should use console.log if no argument given', (done) => {
let stub = sandbox.stub(console, 'log');

const expected = [0, 1, 2];
const stream = xs.periodic(50).take(3).debug();

assert.doesNotThrow(() => {
stream.addListener({
next: (x: number) => {
assert.equal(x, expected.shift());
},
error: (err) => done(err),
complete: () => {
assert.strictEqual(stub.callCount, 3);
assert.strictEqual(stub.firstCall.args[0], 0);
assert.strictEqual(stub.secondCall.args[0], 1);
assert.strictEqual(stub.thirdCall.args[0], 2);
done();
},
});
});
});

it('should return a Stream if input stream is a Stream', (done) => {
const input = xs.of<number>(1, 2, 3);
assert.strictEqual(input instanceof Stream, true);
Expand Down
4 changes: 3 additions & 1 deletion typings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "xstream",
"dependencies": {},
"devDependencies": {},
"devDependencies": {
"sinon": "registry:npm/sinon#1.16.0+20160427193336"
},
"globalDependencies": {
"es6-promise": "registry:dt/es6-promise#0.0.0+20160423074304"
},
Expand Down

0 comments on commit 6cefc81

Please sign in to comment.