File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -94,7 +94,7 @@ class Result {
9494 let onCompletedOriginal = observer . onCompleted ;
9595 let onCompletedWrapper = ( metadata ) => {
9696 this . summary = new ResultSummary ( this . _statement , this . _parameters , metadata ) ;
97- onCompletedOriginal ( metadata ) ;
97+ onCompletedOriginal . call ( observer , metadata ) ;
9898 }
9999 observer . onCompleted = onCompletedWrapper ;
100100 this . _streamObserver . subscribe ( observer ) ;
Original file line number Diff line number Diff line change @@ -22,6 +22,28 @@ describe('session', function() {
2222 } ) ;
2323 } ) ;
2424
25+ it ( 'should keep context in subscribe methods ' , function ( done ) {
26+ // Given
27+ var driver = neo4j . driver ( "neo4j://localhost" ) ;
28+ function myObserver ( ) {
29+ this . local = 'hello' ;
30+ var privateLocal = 'hello' ;
31+ this . onNext = function ( ) {
32+ expect ( privateLocal ) . toBe ( 'hello' ) ;
33+ expect ( this . local ) . toBe ( 'hello' ) ;
34+ } ;
35+ this . onCompleted = function ( ) {
36+ expect ( privateLocal ) . toBe ( 'hello' ) ;
37+ expect ( this . local ) . toBe ( 'hello' ) ;
38+ driver . close ( ) ;
39+ done ( ) ;
40+ }
41+ }
42+
43+ // When & Then
44+ driver . session ( ) . run ( "RETURN 1.0 AS a" ) . subscribe ( new myObserver ( ) ) ;
45+ } ) ;
46+
2547 it ( 'should call observers onError on error ' , function ( done ) {
2648 // Given
2749 var driver = neo4j . driver ( "neo4j://localhost" ) ;
You can’t perform that action at this time.
0 commit comments