Skip to content

Commit 82c31c3

Browse files
committed
Compile error + fix for then then
1 parent 91ca7f6 commit 82c31c3

File tree

4 files changed

+70
-7
lines changed

4 files changed

+70
-7
lines changed

src/v1/driver.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Session from './session';
2121
import {Pool} from './internal/pool';
2222
import {connect} from "./internal/connector";
2323
import StreamObserver from './internal/stream-observer';
24-
import {VERSION} from '../../version';
24+
import {VERSION} from '../version';
2525

2626
/**
2727
* A driver maintains one or more {@link Session sessions} with a remote

src/v1/result.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ class Result {
7474
*/
7575
then(onFulfilled, onRejected) {
7676
this._createPromise();
77-
this._p.then(onFulfilled, onRejected);
78-
return this._p;
77+
return this._p.then(onFulfilled, onRejected);
7978
}
8079

8180
/**
@@ -86,8 +85,7 @@ class Result {
8685
*/
8786
catch(onRejected) {
8887
this._createPromise();
89-
this._p.catch(onRejected);
90-
return this._p;
88+
return this._p.catch(onRejected);
9189
}
9290

9391
/**

test/v1/result.test.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Copyright (c) 2002-2016 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
var neo4j = require("../../lib/v1");
21+
22+
describe('result stream', function() {
23+
24+
var driver, session;
25+
26+
beforeEach(function(done) {
27+
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
28+
session = driver.session();
29+
30+
session.run("MATCH (n) DETACH DELETE n").then(done);
31+
});
32+
33+
afterEach(function() {
34+
driver.close();
35+
});
36+
37+
it('should allow chaining `then`, returning a new thing in each', function(done) {
38+
// When & Then
39+
session.run( "RETURN 1")
40+
.then( function() {
41+
return "first";
42+
})
43+
.then( function(arg) {
44+
expect(arg).toBe( "first" );
45+
return "second";
46+
})
47+
.then( function(arg) {
48+
expect(arg).toBe( "second" );
49+
})
50+
.then(done);
51+
});
52+
53+
it('should allow catching exception thrown in `then`', function(done) {
54+
// When & Then
55+
session.run( "RETURN 1")
56+
.then( function() {
57+
throw new Error("Away with you!");
58+
})
59+
.catch( function(err) {
60+
expect(err.message).toBe( "Away with you!" );
61+
done()
62+
});
63+
});
64+
});

test/v1/session.test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,21 @@ describe('session', function() {
101101
});
102102
});
103103

104-
it('should expose basic run/then/then/then ', function(done) {
104+
it('should expose run/then/then/then ', function(done) {
105105
// When & Then
106106
session.run( "RETURN 1.0 AS a")
107107
.then(
108108
function(result) {
109109
expect(result.records.length).toBe( 1 );
110110
expect(result.records[0]['a']).toBe( 1 );
111+
return result
111112
}
112113
).then(
113114
function(result) {
114115
expect(result.records.length).toBe( 1 );
115116
expect(result.records[0]['a']).toBe( 1 );
116117
}
117-
).then( function() { done(); })
118+
).then( done );
118119
});
119120

120121
it('should expose basic run/catch ', function(done) {

0 commit comments

Comments
 (0)