build: use strict null checks part 4

This commit is contained in:
Kamil Myśliwiec
2024-11-26 14:03:07 +01:00
parent b94b0b910e
commit 5b220df118
39 changed files with 152 additions and 146 deletions

View File

@@ -44,7 +44,7 @@ export async function callModuleBootstrapHook(module: Module): Promise<any> {
const providers = module.getNonAliasProviders();
// Module (class) instance is the first element of the providers array
// Lifecycle hook has to be called once all classes are properly initialized
const [_, moduleClassHost] = providers.shift();
const [_, moduleClassHost] = providers.shift()!;
const instances = [
...module.controllers,
...providers,

View File

@@ -49,7 +49,7 @@ export async function callAppShutdownHook(
const providers = module.getNonAliasProviders();
// Module (class) instance is the first element of the providers array
// Lifecycle hook has to be called once all classes are properly initialized
const [_, moduleClassHost] = providers.shift();
const [_, moduleClassHost] = providers.shift()!;
const instances = [
...module.controllers,
...providers,

View File

@@ -42,7 +42,7 @@ export async function callModuleDestroyHook(module: Module): Promise<any> {
const providers = module.getNonAliasProviders();
// Module (class) instance is the first element of the providers array
// Lifecycle hook has to be called once all classes are properly destroyed
const [_, moduleClassHost] = providers.shift();
const [_, moduleClassHost] = providers.shift()!;
const instances = [
...module.controllers,
...providers,

View File

@@ -38,7 +38,7 @@ export async function callModuleInitHook(module: Module): Promise<void> {
const providers = module.getNonAliasProviders();
// Module (class) instance is the first element of the providers array
// Lifecycle hook has to be called once all classes are properly initialized
const [_, moduleClassHost] = providers.shift();
const [_, moduleClassHost] = providers.shift()!;
const instances = [
...module.controllers,
...providers,

View File

@@ -365,7 +365,7 @@ describe('ClientGrpcProxy', () => {
});
subscription.unsubscribe();
handler(null, 'a');
handler!(null, 'a');
expect(dataSpy.called).to.be.false;
expect(errorSpy.called).to.be.false;
@@ -416,7 +416,7 @@ describe('ClientGrpcProxy', () => {
});
subscription.unsubscribe();
handler(null, 'a');
handler!(null, 'a');
expect(dataSpy.called).to.be.false;
expect(writeSpy.called).to.be.true;
@@ -476,7 +476,7 @@ describe('ClientGrpcProxy', () => {
describe('publish', () => {
it('should throw exception', () => {
expect(() => client['publish'](null, null)).to.throws(Error);
expect(() => client['publish'](null, null!)).to.throws(Error);
});
});
@@ -504,7 +504,7 @@ describe('ClientGrpcProxy', () => {
it('should return root package in case package name is not defined', () => {
const root = {};
expect(client.lookupPackage(root, undefined)).to.be.equal(root);
expect(client.lookupPackage(root, undefined!)).to.be.equal(root);
expect(client.lookupPackage(root, '')).to.be.equal(root);
});
});

View File

@@ -647,7 +647,7 @@ describe('ClientKafka', () => {
it('should throw error when the topic is not being consumed', () => {
client['consumerAssignments'] = {
[topic]: undefined,
[topic]: undefined!,
};
expect(() => client['getReplyTopicPartition'](replyTopic)).to.throw(
@@ -687,7 +687,7 @@ describe('ClientKafka', () => {
assignPacketIdStub = sinon
.stub(client as any, 'assignPacketId')
.callsFake(packet =>
Object.assign(packet, {
Object.assign(packet!, {
id: correlationId,
}),
);

View File

@@ -58,7 +58,7 @@ describe('ClientMqtt', () => {
connectSpy = sinon.stub(client, 'connect');
assignStub = sinon
.stub(client, 'assignPacketId' as any)
.callsFake(packet => Object.assign(packet, { id }));
.callsFake(packet => Object.assign(packet!, { id }));
});
afterEach(() => {
connectSpy.restore();

View File

@@ -88,7 +88,7 @@ describe('ClientNats', () => {
callback = sinon.spy();
assignStub = sinon
.stub(client, 'assignPacketId' as any)
.callsFake(packet => Object.assign(packet, { id }));
.callsFake(packet => Object.assign(packet!, { id }));
subscription = client['publish'](msg, callback);
subscription();

View File

@@ -93,7 +93,7 @@ describe('ClientRedis', () => {
callback = sinon.spy();
assignStub = sinon
.stub(client, 'assignPacketId' as any)
.callsFake(packet => Object.assign(packet, { id }));
.callsFake(packet => Object.assign(packet!, { id }));
getReplyPatternStub = sinon
.stub(client, 'getReplyPattern')
@@ -289,9 +289,9 @@ describe('ClientRedis', () => {
describe('getClientOptions', () => {
it('should return options object with "retryStrategy" and call "createRetryStrategy"', () => {
const createSpy = sinon.spy(client, 'createRetryStrategy');
const { retryStrategy } = client.getClientOptions();
const { retryStrategy } = client.getClientOptions()!;
try {
retryStrategy({} as any);
retryStrategy!({} as any);
} catch {
// No empty
}

View File

@@ -135,7 +135,7 @@ describe('ClientRMQ', function () {
assertQueue: sinon.spy(() => ({})),
prefetch: sinon.spy(),
};
consumeStub = sinon.stub(client, 'consumeChannel').callsFake(() => null);
consumeStub = sinon.stub(client, 'consumeChannel').callsFake(() => null!);
});
afterEach(() => {
consumeStub.restore();

View File

@@ -34,7 +34,7 @@ describe('ExceptionFiltersContext', () => {
const filter = exceptionFilter.create(
new EmptyMetadata(),
() => ({}) as any,
undefined,
undefined!,
);
expect((filter as any).filters).to.be.empty;
});
@@ -47,7 +47,7 @@ describe('ExceptionFiltersContext', () => {
const filter = exceptionFilter.create(
new WithMetadata(),
() => ({}) as any,
undefined,
undefined!,
);
expect((filter as any).filters).to.not.be.empty;
});

View File

@@ -149,7 +149,7 @@ describe('RpcContextCreator', () => {
describe('createGuardsFn', () => {
it('should throw exception when "tryActivate" returns false', () => {
const guardsFn = contextCreator.createGuardsFn([null], null, null);
const guardsFn = contextCreator.createGuardsFn([null], null!, null!)!;
sinon.stub(guardsConsumer, 'tryActivate').callsFake(async () => false);
guardsFn([]).catch(err => expect(err).to.not.be.undefined);
});
@@ -217,12 +217,12 @@ describe('RpcContextCreator', () => {
{
index: 1,
type: 'test',
data: null,
data: null!,
pipes: [],
extractValue: () => null,
},
],
);
)!;
await pipesFn([]);
expect(pipesFn).to.be.a('function');
});

View File

@@ -4,8 +4,8 @@ import {
PATTERN_METADATA,
TRANSPORT_METADATA,
} from '../../constants';
import { Transport } from '../../enums/transport.enum';
import { EventPattern } from '../../decorators/event-pattern.decorator';
import { Transport } from '../../enums/transport.enum';
describe('@EventPattern', () => {
const pattern = { role: 'test' };
@@ -79,7 +79,7 @@ describe('@EventPattern', () => {
Reflect.defineMetadata(
PATTERN_EXTRAS_METADATA,
additionalExtras,
descriptor.value,
descriptor.value!,
)
)())
public static test() {}

View File

@@ -1,10 +1,9 @@
import { expect } from 'chai';
import {
PATTERN_METADATA,
PATTERN_EXTRAS_METADATA,
PATTERN_METADATA,
TRANSPORT_METADATA,
} from '../../constants';
import { Transport } from '../../enums/transport.enum';
import {
GrpcMethod,
GrpcMethodStreamingType,
@@ -12,6 +11,7 @@ import {
GrpcStreamMethod,
MessagePattern,
} from '../../decorators/message-pattern.decorator';
import { Transport } from '../../enums/transport.enum';
describe('@MessagePattern', () => {
const pattern = { role: 'test' };
@@ -61,7 +61,7 @@ describe('@MessagePattern', () => {
Reflect.defineMetadata(
PATTERN_EXTRAS_METADATA,
additionalExtras,
descriptor.value,
descriptor.value!,
)
)())
public static test() {}

View File

@@ -14,7 +14,7 @@ describe('RpcExceptionsHandler', () => {
describe('handle', () => {
it('should method returns expected stream with message when exception is unknown', done => {
const stream$ = handler.handle(new Error(), null);
const stream$ = handler.handle(new Error(), null!);
stream$
.pipe(
catchError((err: any) => {
@@ -33,7 +33,7 @@ describe('RpcExceptionsHandler', () => {
const message = {
custom: 'Unauthorized',
};
const stream$ = handler.handle(new RpcException(message), null);
const stream$ = handler.handle(new RpcException(message), null!);
stream$
.pipe(
catchError((err: any) => {
@@ -47,7 +47,7 @@ describe('RpcExceptionsHandler', () => {
it('should method emit expected status and transform message to json', done => {
const message = 'Unauthorized';
const stream$ = handler.handle(new RpcException(message), null);
const stream$ = handler.handle(new RpcException(message), null!);
stream$
.pipe(
catchError((err: any) => {
@@ -65,7 +65,7 @@ describe('RpcExceptionsHandler', () => {
sinon.stub(handler, 'invokeCustomFilters').returns(observable$);
});
it('should return observable', () => {
const result = handler.handle(new RpcException(''), null);
const result = handler.handle(new RpcException(''), null!);
expect(result).to.be.eql(observable$);
});
});
@@ -77,13 +77,13 @@ describe('RpcExceptionsHandler', () => {
expect((handler as any).filters).to.be.eql(filters);
});
it('should throw exception when passed argument is not an array', () => {
expect(() => handler.setCustomFilters(null)).to.throw();
expect(() => handler.setCustomFilters(null!)).to.throw();
});
});
describe('invokeCustomFilters', () => {
describe('when filters array is empty', () => {
it('should return identity', () => {
expect(handler.invokeCustomFilters(null, null)).to.be.null;
expect(handler.invokeCustomFilters(null, null!)).to.be.null;
});
});
describe('when filters array is not empty', () => {
@@ -99,26 +99,26 @@ describe('RpcExceptionsHandler', () => {
(handler as any).filters = filters;
});
it('should call funcSpy', () => {
handler.invokeCustomFilters(new TestException(), null);
handler.invokeCustomFilters(new TestException(), null!);
expect(funcSpy.notCalled).to.be.false;
});
it('should call funcSpy with exception and response passed as an arguments', () => {
const exception = new TestException();
handler.invokeCustomFilters(exception, null);
handler.invokeCustomFilters(exception, null!);
expect(funcSpy.calledWith(exception)).to.be.true;
});
it('should return stream', () => {
expect(handler.invokeCustomFilters(new TestException(), null)).to.be
expect(handler.invokeCustomFilters(new TestException(), null!)).to.be
.not.null;
});
});
describe('when filter does not exists in filters array', () => {
it('should not call funcSpy', () => {
handler.invokeCustomFilters(new TestException(), null);
handler.invokeCustomFilters(new TestException(), null!);
expect(funcSpy.notCalled).to.be.true;
});
it('should return null', () => {
expect(handler.invokeCustomFilters(new TestException(), null)).to.be
expect(handler.invokeCustomFilters(new TestException(), null!)).to.be
.null;
});
});

View File

@@ -16,7 +16,7 @@ describe('RpcParamsFactory', () => {
describe(`RpcParamtype.PAYLOAD`, () => {
it('should return a message payload object', () => {
expect(
factory.exchangeKeyForValue(RpcParamtype.PAYLOAD, null, args),
factory.exchangeKeyForValue(RpcParamtype.PAYLOAD, null!, args),
).to.be.eql(payload);
});
it('should return a message payload object with parameter extraction', () => {
@@ -28,19 +28,21 @@ describe('RpcParamsFactory', () => {
describe(`RpcParamtype.CONTEXT`, () => {
it('should return a ctx object', () => {
expect(
factory.exchangeKeyForValue(RpcParamtype.CONTEXT, null, args),
factory.exchangeKeyForValue(RpcParamtype.CONTEXT, null!, args),
).to.be.eql(ctx);
});
});
});
describe('when key is not available', () => {
it('should return null', () => {
expect(factory.exchangeKeyForValue(-1, null, [])).to.be.eql(null);
expect(factory.exchangeKeyForValue(-1, null!, [])).to.be.eql(null);
});
});
describe('when args are not available', () => {
it('should return null', () => {
expect(factory.exchangeKeyForValue(null, null, null)).to.be.eql(null);
expect(factory.exchangeKeyForValue(null!, null!, null!)).to.be.eql(
null,
);
});
});
});

View File

@@ -16,31 +16,31 @@ describe('JsonSocket connection', () => {
return done(error);
}
expect(clientSocket['isClosed']).to.be.false;
expect(serverSocket['isClosed']).to.be.false;
expect(clientSocket!['isClosed']).to.be.false;
expect(serverSocket!['isClosed']).to.be.false;
Promise.all([
new Promise(callback => {
clientSocket.sendMessage({ type: 'ping' }, callback);
clientSocket!.sendMessage({ type: 'ping' }, callback);
}),
new Promise<void>(callback => {
clientSocket.on(MESSAGE_EVENT, (message: string) => {
clientSocket!.on(MESSAGE_EVENT, (message: string) => {
expect(message).to.deep.equal({ type: 'pong' });
callback();
});
}),
new Promise(callback => {
serverSocket.on(MESSAGE_EVENT, (message: string) => {
serverSocket!.on(MESSAGE_EVENT, (message: string) => {
expect(message).to.deep.equal({ type: 'ping' });
serverSocket.sendMessage({ type: 'pong' }, callback);
serverSocket!.sendMessage({ type: 'pong' }, callback);
});
}),
])
.then(() => {
expect(clientSocket['isClosed']).to.equal(false);
expect(serverSocket['isClosed']).to.equal(false);
clientSocket.end();
server.close(done);
expect(clientSocket!['isClosed']).to.equal(false);
expect(serverSocket!['isClosed']).to.equal(false);
clientSocket!.end();
server!.close(done);
})
.catch(e => done(e));
},
@@ -52,30 +52,30 @@ describe('JsonSocket connection', () => {
if (err) {
return done(err);
}
expect(clientSocket['isClosed']).to.equal(false);
expect(serverSocket['isClosed']).to.equal(false);
expect(clientSocket!['isClosed']).to.equal(false);
expect(serverSocket!['isClosed']).to.equal(false);
Promise.all([
new Promise<void>(callback => {
clientSocket.sendMessage(longPayload, callback);
clientSocket!.sendMessage(longPayload, callback);
}),
new Promise<void>(callback => {
clientSocket.on(MESSAGE_EVENT, (message: { type: 'pong' }) => {
clientSocket!.on(MESSAGE_EVENT, (message: { type: 'pong' }) => {
expect(message).to.deep.equal({ type: 'pong' });
callback();
});
}),
new Promise<void>(callback => {
serverSocket.on(MESSAGE_EVENT, (message: { type: 'pong' }) => {
serverSocket!.on(MESSAGE_EVENT, (message: { type: 'pong' }) => {
expect(message).to.deep.equal(longPayload);
serverSocket.sendMessage({ type: 'pong' }, callback);
serverSocket!.sendMessage({ type: 'pong' }, callback);
});
}),
])
.then(() => {
expect(clientSocket['isClosed']).to.equal(false);
expect(serverSocket['isClosed']).to.equal(false);
clientSocket.end();
server.close(done);
expect(clientSocket!['isClosed']).to.equal(false);
expect(serverSocket!['isClosed']).to.equal(false);
clientSocket!.end();
server!.close(done);
})
.catch(e => done(e));
});
@@ -94,14 +94,14 @@ describe('JsonSocket connection', () => {
.map(
i =>
new Promise(resolve =>
clientSocket.sendMessage({ number: i }, resolve),
clientSocket!.sendMessage({ number: i }, resolve),
),
),
).then(_ => callback()),
),
new Promise<void>(callback => {
let lastNumber = 0;
serverSocket.on(MESSAGE_EVENT, (message: { number: number }) => {
serverSocket!.on(MESSAGE_EVENT, (message: { number: number }) => {
expect(message.number).to.deep.equal(lastNumber + 1);
lastNumber = message.number;
if (lastNumber === 100) {
@@ -111,8 +111,8 @@ describe('JsonSocket connection', () => {
}),
])
.then(() => {
clientSocket.end();
server.close(done);
clientSocket!.end();
server!.close(done);
})
.catch(e => done(e));
});
@@ -125,20 +125,20 @@ describe('JsonSocket connection', () => {
}
new Promise(callback => {
serverSocket.end();
serverSocket!.end();
setTimeout(callback, 10);
})
.then(
() =>
new Promise<void>(callback => {
expect(clientSocket['isClosed']).to.equal(true);
expect(serverSocket['isClosed']).to.equal(true);
expect(clientSocket!['isClosed']).to.equal(true);
expect(serverSocket!['isClosed']).to.equal(true);
callback();
}),
)
.then(() => {
clientSocket.end();
server.close(done);
clientSocket!.end();
server!.close(done);
})
.catch(e => done(e));
});
@@ -151,18 +151,18 @@ describe('JsonSocket connection', () => {
}
new Promise(callback => {
clientSocket.end();
clientSocket!.end();
setTimeout(callback, 10);
})
.then(
() =>
new Promise<void>(callback => {
expect(clientSocket['isClosed']).to.equal(true);
expect(serverSocket['isClosed']).to.equal(true);
expect(clientSocket!['isClosed']).to.equal(true);
expect(serverSocket!['isClosed']).to.equal(true);
callback();
}),
)
.then(() => server.close(done))
.then(() => server!.close(done))
.catch(e => done(e));
});
});
@@ -176,16 +176,16 @@ describe('JsonSocket connection', () => {
server.once('connection', socket => {
const serverSocket = new JsonSocket(socket);
serverSocket.once('end', () => {
serverSocket!.once('end', () => {
setTimeout(() => {
expect(serverSocket['isClosed']).to.equal(true);
expect(clientSocket['isClosed']).to.equal(true);
expect(serverSocket!['isClosed']).to.equal(true);
expect(clientSocket!['isClosed']).to.equal(true);
clientSocket.on(TcpEventsMap.CONNECT, () => {
clientSocket!.on(TcpEventsMap.CONNECT, () => {
setTimeout(() => {
expect(clientSocket['isClosed']).to.equal(false);
expect(clientSocket!['isClosed']).to.equal(false);
clientSocket.end();
clientSocket!.end();
server.close(done);
}, 10);
});
@@ -196,11 +196,11 @@ describe('JsonSocket connection', () => {
}
const port2 = (address2 as AddressInfo).port;
clientSocket.connect(port2, ip);
clientSocket!.connect(port2, ip);
}, 10);
});
clientSocket.end();
clientSocket!.end();
});
const address1 = server.address();
@@ -209,7 +209,7 @@ describe('JsonSocket connection', () => {
}
const port1 = (address1 as AddressInfo).port;
clientSocket.connect(port1, ip);
clientSocket!.connect(port1, ip);
});
server.listen();
});

View File

@@ -63,7 +63,7 @@ export function createServerAndClient(
return callback(serverErr);
}
createClient(server, (clientErr, clientSocket, serverSocket) => {
createClient(server!, (clientErr, clientSocket, serverSocket) => {
if (clientErr) {
return callback(clientErr);
}
@@ -74,7 +74,7 @@ export function createServerAndClient(
}
export function range(start: number, end: number) {
const r = [];
const r = [] as number[];
for (let i = start; i <= end; i++) {
r.push(i);
}

View File

@@ -12,18 +12,18 @@ describe('JsonSocket chaining', () => {
return done(err);
}
expect(clientSocket.on(MESSAGE_EVENT, () => {})).to.be.instanceof(
expect(clientSocket!.on(MESSAGE_EVENT, () => {})).to.be.instanceof(
JsonSocket,
);
expect(clientSocket.on(TcpEventsMap.CONNECT, () => {})).to.deep.equal(
expect(clientSocket!.on(TcpEventsMap.CONNECT, () => {})).to.deep.equal(
clientSocket,
);
expect(
clientSocket.on(MESSAGE_EVENT, () => {}).on('end', () => {}),
clientSocket!.on(MESSAGE_EVENT, () => {}).on('end', () => {}),
).to.deep.equal(clientSocket);
clientSocket.end();
server.close(done);
clientSocket!.end();
server!.close(done);
});
});
});

View File

@@ -281,7 +281,7 @@ describe('ListenersController', () => {
patterns: ['findOne'],
methodKey: 'find',
isEventHandler: false,
targetCallback: null,
targetCallback: null!,
extras: { qos: 2 },
};
const transportId = Transport.MQTT;

View File

@@ -84,7 +84,7 @@ describe('ListenerMetadataExplorer', () => {
test,
Object.getPrototypeOf(test),
'testMessage',
);
)!;
expect(metadata).to.have.keys([
'isEventHandler',
'methodKey',
@@ -101,7 +101,7 @@ describe('ListenerMetadataExplorer', () => {
test,
Object.getPrototypeOf(test),
'testMultipleMessage',
);
)!;
expect(metadata).to.have.keys([
'isEventHandler',
'methodKey',
@@ -122,7 +122,7 @@ describe('ListenerMetadataExplorer', () => {
test,
Object.getPrototypeOf(test),
'testEvent',
);
)!;
expect(metadata).to.have.keys([
'isEventHandler',
'methodKey',
@@ -139,7 +139,7 @@ describe('ListenerMetadataExplorer', () => {
test,
Object.getPrototypeOf(test),
'testMultipleEvent',
);
)!;
expect(metadata).to.have.keys([
'isEventHandler',
'methodKey',

View File

@@ -26,7 +26,7 @@ describe('ClientsModule', () => {
expect(dynamicModule.module).to.be.eql(ClientsModule);
});
it('should return an expected providers array', () => {
const provider = dynamicModule.providers.find(
const provider = dynamicModule.providers!.find(
p => 'useValue' in p && p.provide === 'test',
) as ValueProvider;
expect(provider).to.not.be.undefined;
@@ -56,7 +56,7 @@ describe('ClientsModule', () => {
expect(dynamicModule.exports).to.be.eq(dynamicModule.providers);
expect(dynamicModule.providers).to.be.have.length(1);
const provider = dynamicModule.providers[0] as FactoryProvider;
const provider = dynamicModule.providers![0] as FactoryProvider;
expect(provider.provide).to.be.eql('test');
expect(provider.inject).to.be.deep.eq([]);
expect(provider.useFactory).to.be.an.instanceOf(Function);
@@ -82,7 +82,8 @@ describe('ClientsModule', () => {
expect(dynamicModule.imports).to.be.deep.eq([]);
expect(dynamicModule.providers).to.be.have.length(2);
const classTestProvider = dynamicModule.providers[0] as FactoryProvider;
const classTestProvider = dynamicModule
.providers![0] as FactoryProvider;
expect(classTestProvider.provide).to.be.eql('classTest');
expect(classTestProvider.inject).to.be.deep.eq([ClientOptionService]);
expect(classTestProvider.useFactory).to.be.an.instanceOf(Function);
@@ -98,7 +99,7 @@ describe('ClientsModule', () => {
createClientOptions: sinon.spy(),
};
try {
await (dynamicModule.providers[0] as any).useFactory(optionsFactory);
await (dynamicModule.providers![0] as any).useFactory(optionsFactory);
} catch (e) {
console.log(e);
}
@@ -114,7 +115,8 @@ describe('ClientsModule', () => {
dynamicModule = ClientsModule.registerAsync([asyncOptions as any]);
expect(dynamicModule.providers).to.have.length(1);
expect(dynamicModule.imports).to.be.deep.eq([]);
const classTestProvider = dynamicModule.providers[0] as FactoryProvider;
const classTestProvider = dynamicModule
.providers![0] as FactoryProvider;
expect(classTestProvider.useFactory).to.be.an.instanceOf(Function);
});
});

View File

@@ -731,7 +731,7 @@ describe('ServerGrpc', () => {
write: sinon.spy(() => true),
};
await fn(call as any, null);
await fn(call as any, null!);
expect(call.write.called).to.be.true;
expect(call.end.called).to.be.true;

View File

@@ -265,8 +265,8 @@ describe('ServerKafka', () => {
it('should call "handleMessage"', async () => {
const handleMessageStub = sinon
.stub(server, 'handleMessage')
.callsFake(() => null);
await server.getMessageHandler()(null);
.callsFake(() => null!);
await server.getMessageHandler()(null!);
expect(handleMessageStub.called).to.be.true;
});
});
@@ -287,7 +287,7 @@ describe('ServerKafka', () => {
.callsFake(async () => []);
});
it(`should return function`, () => {
expect(typeof server.getPublisher(null, null, correlationId)).to.be.eql(
expect(typeof server.getPublisher(null!, null!, correlationId)).to.be.eql(
'function',
);
});
@@ -393,7 +393,9 @@ describe('ServerKafka', () => {
await server.handleMessage(payload);
expect(
getPublisherSpy.calledWith({
id: payload.message.headers[KafkaHeaders.CORRELATION_ID].toString(),
id: payload.message!.headers![
KafkaHeaders.CORRELATION_ID
]!.toString(),
err: NO_MESSAGE_HANDLER,
}),
).to.be.true;
@@ -453,7 +455,7 @@ describe('ServerKafka', () => {
response: messageValue,
},
replyTopic,
undefined,
undefined!,
correlationId,
);

View File

@@ -103,11 +103,11 @@ describe('ServerMqtt', () => {
it('should call "handleMessage"', async () => {
const handleMessageStub = sinon
.stub(server, 'handleMessage')
.callsFake(() => null);
.callsFake(() => null!);
await server.getMessageHandler(untypedServer.mqttClient)(
null,
null,
null,
null!,
null!,
null!,
);
expect(handleMessageStub.called).to.be.true;
});

View File

@@ -140,13 +140,13 @@ describe('ServerNats', () => {
});
describe('getMessageHandler', () => {
it(`should return function`, () => {
expect(typeof server.getMessageHandler(null)).to.be.eql('function');
expect(typeof server.getMessageHandler(null!)).to.be.eql('function');
});
describe('handler', () => {
it('should call "handleMessage"', async () => {
const handleMessageStub = sinon
.stub(server, 'handleMessage')
.callsFake(() => null);
.callsFake(() => null!);
await server.getMessageHandler('')('' as any, '');
expect(handleMessageStub.called).to.be.true;
});

View File

@@ -223,9 +223,9 @@ describe('ServerRedis', () => {
describe('getClientOptions', () => {
it('should return options object with "retryStrategy" and call "createRetryStrategy"', () => {
const createSpy = sinon.spy(server, 'createRetryStrategy');
const { retryStrategy } = server.getClientOptions();
const { retryStrategy } = server.getClientOptions()!;
try {
retryStrategy(0);
retryStrategy!(0);
} catch {
// Ignore
}

View File

@@ -21,7 +21,7 @@ describe('ServerTCP', () => {
sinon.stub(server, 'getSocketInstance' as any).callsFake(() => socket);
});
it('should bind message and error events to handler', () => {
server.bindHandler(null);
server.bindHandler(null!);
expect(socket.on.calledTwice).to.be.true;
});
});

View File

@@ -9,7 +9,7 @@ class TestServer extends Server {
EventCallback extends Function = Function,
>(event: EventKey, callback: EventCallback) {}
public unwrap<T>(): T {
return null;
return null!;
}
public listen(callback: () => void) {}
public close() {}

View File

@@ -44,7 +44,7 @@ describe('transformPatternToRoute', () => {
controller: 'app',
id: 150,
},
];
] as MsPattern[];
const expectedResults = [
JSON.stringify(testPatterns[0]),
@@ -71,7 +71,7 @@ describe('transformPatternToRoute', () => {
use: { p1: 'path1', p2: 'path2', id: 160 },
controller: 'app',
},
];
] as MsPattern[];
const expectedResults = [
JSON.stringify(testPatterns[0]),
@@ -98,7 +98,7 @@ describe('transformPatternToRoute', () => {
use: { p1: 'path1', p2: { pp1: 'ppath1' } },
controller: { p1: { pp1: 'ppath1', id: 180 } },
},
];
] as MsPattern[];
const expectedResults = [
JSON.stringify(testPatterns[0]),

View File

@@ -1,8 +1,8 @@
import { FactoryProvider } from '@nestjs/common';
import { expect } from 'chai';
import * as sinon from 'sinon';
import { MULTER_MODULE_OPTIONS } from '../../../multer/files.constants';
import { MulterModule } from '../../../multer/multer.module';
import { FactoryProvider } from '@nestjs/common';
describe('MulterModule', () => {
describe('register', () => {
@@ -16,7 +16,7 @@ describe('MulterModule', () => {
expect(dynamicModule.imports).to.be.undefined;
expect(dynamicModule.exports).to.include(MULTER_MODULE_OPTIONS);
const moduleOptionsProvider = dynamicModule.providers.find(
const moduleOptionsProvider = dynamicModule.providers!.find(
p => 'useFactory' in p && p.provide === MULTER_MODULE_OPTIONS,
) as FactoryProvider;
expect(moduleOptionsProvider).to.not.be.undefined;
@@ -76,7 +76,7 @@ describe('MulterModule', () => {
const optionsFactory = {
createMulterOptions: sinon.spy(),
};
await (dynamicModule.providers[0] as any).useFactory(optionsFactory);
await (dynamicModule.providers![0] as any).useFactory(optionsFactory);
expect(optionsFactory.createMulterOptions.called).to.be.true;
});
});

View File

@@ -5,8 +5,8 @@ import {
} from '@nestjs/common';
import { expect } from 'chai';
import {
multerExceptions,
busboyExceptions,
multerExceptions,
} from '../../../multer/multer/multer.constants';
import { transformException } from '../../../multer/multer/multer.utils';
@@ -63,7 +63,7 @@ describe('transformException', () => {
message: multerExceptions.LIMIT_UNEXPECTED_FILE,
field: 'foo',
};
expect(transformException(err as any).message).to.equal(
expect(transformException(err as any)!.message).to.equal(
`${multerExceptions.LIMIT_UNEXPECTED_FILE} - foo`,
);
});

View File

@@ -6,7 +6,6 @@ import { NestContainer } from '../../../core/injector/container';
import { ExceptionFiltersContext } from '../../context/exception-filters-context';
describe('ExceptionFiltersContext', () => {
let moduleName: string;
let exceptionFilter: ExceptionFiltersContext;
class CustomException {}
@@ -16,7 +15,6 @@ describe('ExceptionFiltersContext', () => {
}
beforeEach(() => {
moduleName = 'Test';
exceptionFilter = new ExceptionFiltersContext(new NestContainer() as any);
});
describe('create', () => {

View File

@@ -144,7 +144,7 @@ describe('WsContextCreator', () => {
describe('createGuardsFn', () => {
it('should throw exception when "tryActivate" returns false', () => {
const guardsFn = contextCreator.createGuardsFn([null], null, null);
const guardsFn = contextCreator.createGuardsFn([null], null!, null!)!;
sinon.stub(guardsConsumer, 'tryActivate').callsFake(async () => false);
guardsFn([]).catch(err => expect(err).to.not.be.undefined);
});
@@ -211,12 +211,12 @@ describe('WsContextCreator', () => {
{
index: 1,
type: 'test',
data: null,
data: null!,
pipes: [],
extractValue: () => null,
},
],
);
)!;
await pipesFn([]);
expect(pipesFn).to.be.a('function');
});

View File

@@ -121,13 +121,13 @@ describe('WsExceptionsHandler', () => {
expect((handler as any).filters).to.be.eql(filters);
});
it('should throw exception when passed argument is not an array', () => {
expect(() => handler.setCustomFilters(null)).to.throw();
expect(() => handler.setCustomFilters(null!)).to.throw();
});
});
describe('invokeCustomFilters', () => {
describe('when filters array is empty', () => {
it('should return false', () => {
expect(handler.invokeCustomFilters(null, null)).to.be.false;
expect(handler.invokeCustomFilters(null, null!)).to.be.false;
});
});
describe('when filters array is not empty', () => {
@@ -143,7 +143,7 @@ describe('WsExceptionsHandler', () => {
(handler as any).filters = filters;
});
it('should call funcSpy', () => {
handler.invokeCustomFilters(new TestException(), null);
handler.invokeCustomFilters(new TestException(), null!);
expect(funcSpy.notCalled).to.be.false;
});
it('should call funcSpy with exception and response passed as an arguments', () => {
@@ -154,17 +154,17 @@ describe('WsExceptionsHandler', () => {
expect(funcSpy.calledWith(exception, res)).to.be.true;
});
it('should return true', () => {
expect(handler.invokeCustomFilters(new TestException(), null)).to.be
expect(handler.invokeCustomFilters(new TestException(), null!)).to.be
.true;
});
});
describe('when filter does not exists in filters array', () => {
it('should not call funcSpy', () => {
handler.invokeCustomFilters(new TestException(), null);
handler.invokeCustomFilters(new TestException(), null!);
expect(funcSpy.notCalled).to.be.true;
});
it('should return false', () => {
expect(handler.invokeCustomFilters(new TestException(), null)).to.be
expect(handler.invokeCustomFilters(new TestException(), null!)).to.be
.false;
});
});

View File

@@ -16,7 +16,7 @@ describe('WsParamsFactory', () => {
describe(`WsParamtype.PAYLOAD`, () => {
it('should return a message payload object', () => {
expect(
factory.exchangeKeyForValue(WsParamtype.PAYLOAD, null, args),
factory.exchangeKeyForValue(WsParamtype.PAYLOAD, null!, args),
).to.be.eql(data);
});
it('should return a message payload object with parameter extraction', () => {
@@ -28,19 +28,21 @@ describe('WsParamsFactory', () => {
describe(`WsParamtype.SOCKET`, () => {
it('should return a connected socket object', () => {
expect(
factory.exchangeKeyForValue(WsParamtype.SOCKET, null, args),
factory.exchangeKeyForValue(WsParamtype.SOCKET, null!, args),
).to.be.eql(client);
});
});
});
describe('when key is not available', () => {
it('should return null', () => {
expect(factory.exchangeKeyForValue(-1, null, [])).to.be.eql(null);
expect(factory.exchangeKeyForValue(-1, null!, [])).to.be.eql(null);
});
});
describe('when args are not available', () => {
it('should return null', () => {
expect(factory.exchangeKeyForValue(null, null, null)).to.be.eql(null);
expect(factory.exchangeKeyForValue(null!, null!, null!)).to.be.eql(
null,
);
});
});
});

View File

@@ -60,7 +60,7 @@ describe('GatewayMetadataExplorer', () => {
expect(metadata).to.eq(null);
});
it(`should return message mapping properties when "isMessageMapping" metadata is not undefined`, () => {
const metadata = instance.exploreMethodMetadata(test, 'test');
const metadata = instance.exploreMethodMetadata(test, 'test')!;
expect(metadata).to.have.keys(['callback', 'message', 'methodName']);
expect(metadata.message).to.eql(message);
});

View File

@@ -38,7 +38,7 @@ describe('SocketServerProvider', () => {
const server = { test: 'test' };
mockContainer.expects('getOneByConfig').returns(server);
const result = instance.scanForSocketServer({ namespace: null }, port);
const result = instance.scanForSocketServer({ namespace: null! }, port);
expect(createSocketServerSpy.called).to.be.false;
expect(result).to.eq(server);

View File

@@ -47,7 +47,7 @@ describe('WebSocketsController', () => {
beforeEach(() => {
config = new ApplicationConfig(new NoopAdapter());
provider = new SocketServerProvider(null, config);
provider = new SocketServerProvider(null!, config);
graphInspector = new GraphInspector(new NestContainer());
mockProvider = sinon.mock(provider);
@@ -187,12 +187,12 @@ describe('WebSocketsController', () => {
{
methodName: 'findOne',
message: 'find',
callback: null,
callback: null!,
},
{
methodName: 'create',
message: 'insert',
callback: null,
callback: null!,
},
];
const insertEntrypointDefinitionSpy = sinon.spy(
@@ -337,7 +337,7 @@ describe('WebSocketsController', () => {
instance,
gateway,
handlers,
null,
null!,
connection,
);
fn(client);
@@ -345,7 +345,7 @@ describe('WebSocketsController', () => {
it('should return function', () => {
expect(
instance.getConnectionHandler(null, null, null, null, null),
instance.getConnectionHandler(null!, null!, null!, null!, null!),
).to.be.a('function');
});
it('should call "next" method of connection object with expected argument', () => {