From 4621fad49ba4f8673ad1fd3c4dfce87ac59adae9 Mon Sep 17 00:00:00 2001 From: zmj Date: Mon, 6 Dec 2021 20:53:11 +0800 Subject: [PATCH] refactor(): replace `indexOf` with `includes` --- integration/microservices/e2e/orders-grpc.spec.ts | 4 ++-- integration/microservices/e2e/sum-grpc.spec.ts | 4 ++-- packages/common/pipes/parse-enum.pipe.ts | 2 +- packages/microservices/server/server-mqtt.ts | 3 +-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/integration/microservices/e2e/orders-grpc.spec.ts b/integration/microservices/e2e/orders-grpc.spec.ts index 82f1d69e0d1..d3c293ef6fe 100644 --- a/integration/microservices/e2e/orders-grpc.spec.ts +++ b/integration/microservices/e2e/orders-grpc.spec.ts @@ -134,7 +134,7 @@ describe('Advanced GRPC transport', () => { callHandler.on('error', (err: any) => { // We want to fail only on real errors while Cancellation error // is expected - if (String(err).toLowerCase().indexOf('cancelled') === -1) { + if (!String(err).toLowerCase().includes('cancelled')) { fail('gRPC Stream error happened, error: ' + err); } }); @@ -166,7 +166,7 @@ describe('Advanced GRPC transport', () => { callHandler.on('error', (err: any) => { // We want to fail only on real errors while Cancellation error // is expected - if (String(err).toLowerCase().indexOf('cancelled') === -1) { + if (!String(err).toLowerCase().includes('cancelled')) { fail('gRPC Stream error happened, error: ' + err); } }); diff --git a/integration/microservices/e2e/sum-grpc.spec.ts b/integration/microservices/e2e/sum-grpc.spec.ts index 23cc9a88644..d292c3c2100 100644 --- a/integration/microservices/e2e/sum-grpc.spec.ts +++ b/integration/microservices/e2e/sum-grpc.spec.ts @@ -78,7 +78,7 @@ describe('GRPC transport', () => { callHandler.on('error', (err: any) => { // We want to fail only on real errors while Cancellation error // is expected - if (String(err).toLowerCase().indexOf('cancelled') === -1) { + if (!String(err).toLowerCase().includes('cancelled')) { fail('gRPC Stream error happened, error: ' + err); } }); @@ -100,7 +100,7 @@ describe('GRPC transport', () => { callHandler.on('error', (err: any) => { // We want to fail only on real errors while Cancellation error // is expected - if (String(err).toLowerCase().indexOf('cancelled') === -1) { + if (!String(err).toLowerCase().includes('cancelled')) { fail('gRPC Stream error happened, error: ' + err); } }); diff --git a/packages/common/pipes/parse-enum.pipe.ts b/packages/common/pipes/parse-enum.pipe.ts index 4f0fc853781..406f617277d 100644 --- a/packages/common/pipes/parse-enum.pipe.ts +++ b/packages/common/pipes/parse-enum.pipe.ts @@ -59,6 +59,6 @@ export class ParseEnumPipe implements PipeTransform { const enumValues = Object.keys(this.enumType).map( item => this.enumType[item], ); - return enumValues.indexOf(value) >= 0; + return enumValues.includes(value); } } diff --git a/packages/microservices/server/server-mqtt.ts b/packages/microservices/server/server-mqtt.ts index b57c6c5195d..1867a1a3a4d 100644 --- a/packages/microservices/server/server-mqtt.ts +++ b/packages/microservices/server/server-mqtt.ts @@ -191,8 +191,7 @@ export class ServerMqtt extends Server implements CustomTransportStrategy { for (const [key, value] of this.messageHandlers) { if ( - key.indexOf(MQTT_WILDCARD_SINGLE) === -1 && - key.indexOf(MQTT_WILDCARD_ALL) === -1 + !key.includes(MQTT_WILDCARD_SINGLE) && !key.includes(MQTT_WILDCARD_ALL) ) { continue; }