Skip to content

Commit 3acf245

Browse files
committed
Fix flaky test by using a more generic error assertion
1 parent 755520a commit 3acf245

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

test/v1/bolt-v3.test.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,7 @@ describe('Bolt V3 API', () => {
9292
session.run('MATCH (n:Node) SET n.prop = $newValue', {newValue: 2}, {timeout: 1})
9393
.then(() => done.fail('Failure expected'))
9494
.catch(error => {
95-
const hasExpectedCode = error.code.indexOf('TransientError') !== -1;
96-
const hasExpectedMessage = error.message.indexOf('transaction has been terminated') !== -1;
97-
if (!hasExpectedCode || !hasExpectedMessage) {
98-
console.log(`Unexpected error with code ${error.code}`, error);
99-
}
100-
expect(hasExpectedCode).toBeTruthy();
101-
expect(hasExpectedMessage).toBeTruthy();
95+
expectTransactionTerminatedError(error);
10296

10397
tx.rollback()
10498
.then(() => otherSession.close())
@@ -185,8 +179,7 @@ describe('Bolt V3 API', () => {
185179
tx.run('MATCH (n:Node) SET n.prop = $newValue', {newValue: 2})
186180
.then(() => done.fail('Failure expected'))
187181
.catch(error => {
188-
expect(error.code.indexOf('TransientError')).toBeGreaterThan(0);
189-
expect(error.message.indexOf('transaction has been terminated')).toBeGreaterThan(0);
182+
expectTransactionTerminatedError(error);
190183

191184
otherTx.rollback()
192185
.then(() => otherSession.close())
@@ -467,6 +460,14 @@ describe('Bolt V3 API', () => {
467460
expect(error.message.indexOf('Driver is connected to the database that does not support transaction configuration')).toBeGreaterThan(-1);
468461
}
469462

463+
function expectTransactionTerminatedError(error) {
464+
const hasExpectedMessage = error.message.toLowerCase().indexOf('transaction has been terminated') > -1;
465+
if (!hasExpectedMessage) {
466+
console.log(`Unexpected error with code: ${error.code}`, error);
467+
}
468+
expect(hasExpectedMessage).toBeTruthy();
469+
}
470+
470471
function databaseSupportsBoltV3() {
471472
return serverVersion.compareTo(VERSION_3_5_0) >= 0;
472473
}

0 commit comments

Comments
 (0)