test cases - logger.middleware - fixed broken tests
MODIFY
src/middlewares/logger.middleware.spec.ts
src/middlewares/logger.middleware.spec.ts
@@ -16,7 +16,7 @@ describe('Logger middleware', () => {
spyOn(console, 'error').and.stub();
});
- it('reacts to 200 status on the console', async () => {
+ it('reacts to 200 status on the console', () => {
const request = createMockReq('/', 'GET');
const response = createMockRes(200);
@@ -26,11 +26,10 @@ describe('Logger middleware', () => {
], { response });
response.emit('finish');
-
- setTimeout(() => expect(console.log).toHaveBeenCalled(), 10);
+ expect(console.info).toHaveBeenCalled();
});
- it('reacts to 400 status on the console', async () => {
+ it('reacts to 400 status on the console', () => {
const request = createMockReq('/test', 'POST');
const response = createMockRes(403);
@@ -40,8 +39,7 @@ describe('Logger middleware', () => {
], { response });
response.emit('finish');
-
- setTimeout(() => expect(console.log).toHaveBeenCalled(), 10);
+ expect(console.info).toHaveBeenCalled();
});
});

MODIFY
src/middlewares/logger.middleware.ts
src/middlewares/logger.middleware.ts
import chalk from 'chalk';
import { tap } from 'rxjs/operators';
-import { HttpRequest } from '../http.interface';
import { Effect } from '../effects/effects.interface';
+import { HttpRequest } from '../http.interface';
const getStatusCode = (statusCode: number): string =>
statusCode >= 400

test cases - logger.middleware - fixed broken tests