-
Notifications
You must be signed in to change notification settings - Fork 62
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
fix: UnhandledPromiseRejection errors #782
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,32 +18,34 @@ import { of as observableOf, of } from 'rxjs'; | |
import { catchError, map } from 'rxjs/operators'; | ||
import { NetworkConfigurationDTO } from 'symbol-openapi-typescript-fetch-client'; | ||
import { instance, mock, when } from 'ts-mockito'; | ||
import { AccountHttp } from '../../src/infrastructure/AccountHttp'; | ||
import { BlockHttp } from '../../src/infrastructure/BlockHttp'; | ||
import { ChainHttp } from '../../src/infrastructure/ChainHttp'; | ||
import { FinalizationHttp } from '../../src/infrastructure/FinalizationHttp'; | ||
import { HashLockHttp } from '../../src/infrastructure/HashLockHttp'; | ||
import { Listener } from '../../src/infrastructure/Listener'; | ||
import { MetadataHttp } from '../../src/infrastructure/MetadataHttp'; | ||
import { MosaicHttp } from '../../src/infrastructure/MosaicHttp'; | ||
import { MultisigHttp } from '../../src/infrastructure/MultisigHttp'; | ||
import { NamespaceHttp } from '../../src/infrastructure/NamespaceHttp'; | ||
import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; | ||
import { NetworkHttp } from '../../src/infrastructure/NetworkHttp'; | ||
import { NetworkRepository } from '../../src/infrastructure/NetworkRepository'; | ||
import { NodeHttp } from '../../src/infrastructure/NodeHttp'; | ||
import { NodeRepository } from '../../src/infrastructure/NodeRepository'; | ||
import { ReceiptHttp } from '../../src/infrastructure/ReceiptHttp'; | ||
import { RepositoryFactoryHttp } from '../../src/infrastructure/RepositoryFactoryHttp'; | ||
import { RestrictionAccountHttp } from '../../src/infrastructure/RestrictionAccountHttp'; | ||
import { RestrictionMosaicHttp } from '../../src/infrastructure/RestrictionMosaicHttp'; | ||
import { SecretLockHttp } from '../../src/infrastructure/SecretLockHttp'; | ||
import { TransactionGroup } from '../../src/infrastructure/TransactionGroup'; | ||
import { TransactionHttp } from '../../src/infrastructure/TransactionHttp'; | ||
import { TransactionStatusHttp } from '../../src/infrastructure/TransactionStatusHttp'; | ||
import { NetworkCurrencies } from '../../src/model/mosaic/NetworkCurrencies'; | ||
import { NetworkType } from '../../src/model/network/NetworkType'; | ||
import { NodeInfo } from '../../src/model/node/NodeInfo'; | ||
import { | ||
AccountHttp, | ||
BlockHttp, | ||
ChainHttp, | ||
FinalizationHttp, | ||
HashLockHttp, | ||
Listener, | ||
MetadataHttp, | ||
MosaicHttp, | ||
MultisigHttp, | ||
NamespaceHttp, | ||
NamespaceRepository, | ||
NetworkHttp, | ||
NetworkRepository, | ||
NodeHttp, | ||
NodeRepository, | ||
ReceiptHttp, | ||
RepositoryFactoryHttp, | ||
RestrictionAccountHttp, | ||
RestrictionMosaicHttp, | ||
SecretLockHttp, | ||
TransactionGroup, | ||
TransactionHttp, | ||
TransactionStatusHttp, | ||
} from '../../src/infrastructure'; | ||
import { NetworkCurrencies } from '../../src/model/mosaic'; | ||
import { NetworkType } from '../../src/model/network'; | ||
import { NodeInfo } from '../../src/model/node'; | ||
|
||
describe('RepositoryFactory', () => { | ||
it('Should create repositories', () => { | ||
|
@@ -70,6 +72,17 @@ describe('RepositoryFactory', () => { | |
expect(repositoryFactory.createFinalizationRepository()).to.be.not.null; | ||
}); | ||
|
||
it('Raise error without unhandled-rejections', async () => { | ||
const url = 'https://www.google.com'; | ||
const repositoryFactory = new RepositoryFactoryHttp(url); | ||
try { | ||
await repositoryFactory.createNodeRepository().getNodeHealth().toPromise(); | ||
expect(true).to.be.false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we use chai-as-promised or a similar promise assertion library as a better practice in general for promise assertions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! chai as promises looks nice. Although the try-catch could be more end-user-style assertion? And I wouldn't add another lib just yet. Let's consider it for the future. |
||
} catch (e) { | ||
expect(e.message).contains('{"statusCode":404,"statusMessage":"Not Found","body":"<!DOCTYPE html>'); | ||
} | ||
}); | ||
|
||
it('Should get GenerationHash from cache', (done) => { | ||
let counter = 0; | ||
const repositoryMock: NodeRepository = mock(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any other way to achieve this without relying on a remote call? I think we can use
sinon
to stub thegetNodeHealth
method to throw an error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS SDK uses ts-mockito. I've mocked the low-level generated NodeRoutesApi reflecting how it rejects responses with the current mock lib. The (nodeRepository as any).nodeRoutesApi doesn't look nice, but well.