Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test if connect() throw an unhandled exception #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/client-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,35 @@ describe('browserbox integration tests', () => {
return imap.close()
})
})

it('should not throw unhandled rejection when connecting on a wrong server', function () {
return new Promise((resolve, reject) => {
process.on('unhandledRejection', reject)

imap = new ImapClient('bluehope.xyz', 465, {
logLevel,
auth: {
user: 'invalid',
pass: 'invalid'
},
useSecureTransport: true
})

imap.connect().then(() => {
expect(false)
}).catch((err) => {
expect(err).to.be.an('error')
expect(err.message).to.include('Unexpected char at position')
}).then(() => {
// must wait after current loop otherwise unhandledRejection is called after the end of the test.
return new Promise((resolve) => setImmediate(resolve))
}).then(() => {
process.off('unhandledRejection', reject)
}).then(() => {
resolve()
})
})
})

it('should fail authentication', (done) => {
imap = new ImapClient('127.0.0.1', port + 2, {
Expand Down
2 changes: 1 addition & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default class Client {
clearTimeout(connectionTimeout)
this._changeState(STATE_NOT_AUTHENTICATED)
this.updateCapability()
.then(() => resolve(this._capability))
.then(() => resolve(this._capability), reject)
}

this.client.onerror = (err) => {
Expand Down