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 {
94
94
let onCompletedOriginal = observer . onCompleted ;
95
95
let onCompletedWrapper = ( metadata ) => {
96
96
this . summary = new ResultSummary ( this . _statement , this . _parameters , metadata ) ;
97
- onCompletedOriginal ( metadata ) ;
97
+ onCompletedOriginal . call ( observer , metadata ) ;
98
98
}
99
99
observer . onCompleted = onCompletedWrapper ;
100
100
this . _streamObserver . subscribe ( observer ) ;
Original file line number Diff line number Diff line change @@ -22,6 +22,28 @@ describe('session', function() {
22
22
} ) ;
23
23
} ) ;
24
24
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
+
25
47
it ( 'should call observers onError on error ' , function ( done ) {
26
48
// Given
27
49
var driver = neo4j . driver ( "neo4j://localhost" ) ;
You can’t perform that action at this time.
0 commit comments