Skip to content

Commit

Permalink
[Test] Fix console error in search_service.test.ts  (#595)
Browse files Browse the repository at this point in the history
Run unit test suite search_service.test.ts has a console error:
```
UnhandledPromiseRejectionWarning: TypeError: Cannot read
property 'aggs' of undefined
```

This is caused by a missing promise result check in the setup fun
in search_service.ts. If the promise result is empty (or null/undefined),
then any properties of the empty result is undefined. In our case,
`aggs` in `if (value.search.aggs.shardDelay.enabled)` is undefined.
In this PR, we fixed this issue by adding a value check in setup fun.

Issues resolved:
#594

Signed-off-by: Anan Zhuang <[email protected]>
  • Loading branch information
ananzh authored Jul 26, 2021
1 parent 1bf8b96 commit 2b5b672
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/plugins/data/server/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
.pipe(first())
.toPromise()
.then((value) => {
if (value.search.aggs.shardDelay.enabled) {
if (value?.search?.aggs?.shardDelay?.enabled) {
aggs.types.registerBucket(SHARD_DELAY_AGG_NAME, getShardDelayBucketAgg);
registerFunction(aggShardDelay);
}
Expand Down

0 comments on commit 2b5b672

Please sign in to comment.