-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(executeOperation): test throwing of errors in executeOperation
- Loading branch information
1 parent
8a26081
commit b7bc5c3
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const executeOperation = require('../../lib/utils').executeOperation; | ||
|
||
describe('executeOperation', function() { | ||
it('should call callback with errors on throw errors, and rethrow error', function() { | ||
const expectedError = new Error('THIS IS AN ERROR'); | ||
let callbackError, caughtError; | ||
|
||
const topology = { | ||
logicalSessionTimeoutMinutes: null, | ||
s: { | ||
promiseLibrary: Promise | ||
} | ||
}; | ||
const operation = () => { | ||
throw expectedError; | ||
}; | ||
|
||
const callback = err => (callbackError = err); | ||
const options = { skipSessions: true }; | ||
|
||
try { | ||
executeOperation(topology, operation, [{}, callback], options); | ||
} catch (e) { | ||
caughtError = e; | ||
} | ||
|
||
expect(callbackError).to.equal(expectedError); | ||
expect(caughtError).to.equal(expectedError); | ||
}); | ||
|
||
it('should reject promise with errors on throw errors, and rethrow error', function(done) { | ||
const expectedError = new Error('THIS IS AN ERROR'); | ||
let callbackError; | ||
|
||
const topology = { | ||
logicalSessionTimeoutMinutes: null, | ||
s: { | ||
promiseLibrary: Promise | ||
} | ||
}; | ||
const operation = () => { | ||
throw expectedError; | ||
}; | ||
|
||
const callback = err => (callbackError = err); | ||
const options = { skipSessions: true }; | ||
|
||
executeOperation(topology, operation, [{}, null], options).then(null, callback); | ||
|
||
setTimeout(() => { | ||
try { | ||
expect(callbackError).to.equal(expectedError); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}); | ||
}); | ||
}); |