Skip to content

Commit 8b81fc6

Browse files
committed
fix(bindNodeCallback): emit undefined when callback has no success arguments
Emit undefined insteady of empty array by resulting Observable, when callback function is called without success parameters. Closes #2254
1 parent 6ce4773 commit 8b81fc6

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

spec/observables/bindNodeCallback-spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@ const Observable = Rx.Observable;
88
/** @test {bindNodeCallback} */
99
describe('Observable.bindNodeCallback', () => {
1010
describe('when not scheduled', () => {
11+
it('should emit undefined when callback is called without success arguments', () => {
12+
function callback(cb) {
13+
cb(null);
14+
}
15+
16+
const boundCallback = Observable.bindNodeCallback(callback);
17+
const results = [];
18+
19+
boundCallback()
20+
.subscribe((x: any) => {
21+
results.push(typeof x);
22+
}, null, () => {
23+
results.push('done');
24+
});
25+
26+
expect(results).to.deep.equal(['undefined', 'done']);
27+
});
28+
1129
it('should emit one value from a callback', () => {
1230
function callback(datum, cb) {
1331
cb(null, datum);
@@ -126,6 +144,26 @@ describe('Observable.bindNodeCallback', () => {
126144
});
127145

128146
describe('when scheduled', () => {
147+
it('should emit undefined when callback is called without success arguments', () => {
148+
function callback(cb) {
149+
cb(null);
150+
}
151+
152+
const boundCallback = Observable.bindNodeCallback(callback, null, rxTestScheduler);
153+
const results = [];
154+
155+
boundCallback()
156+
.subscribe((x: any) => {
157+
results.push(typeof x);
158+
}, null, () => {
159+
results.push('done');
160+
});
161+
162+
rxTestScheduler.flush();
163+
164+
expect(results).to.deep.equal(['undefined', 'done']);
165+
});
166+
129167
it('should emit one value from a callback', () => {
130168
function callback(datum, cb) {
131169
cb(null, datum);

src/observable/BoundNodeCallbackObservable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class BoundNodeCallbackObservable<T> extends Observable<T> {
112112
subject.complete();
113113
}
114114
} else {
115-
subject.next(innerArgs.length === 1 ? innerArgs[0] : innerArgs);
115+
subject.next(innerArgs.length <= 1 ? innerArgs[0] : innerArgs);
116116
subject.complete();
117117
}
118118
};
@@ -162,7 +162,7 @@ function dispatch<T>(this: Action<DispatchState<T>>, state: DispatchState<T>) {
162162
self.add(scheduler.schedule(dispatchNext, 0, { value: result, subject }));
163163
}
164164
} else {
165-
const value = innerArgs.length === 1 ? innerArgs[0] : innerArgs;
165+
const value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs;
166166
self.add(scheduler.schedule(dispatchNext, 0, { value, subject }));
167167
}
168168
};

0 commit comments

Comments
 (0)