test cases - http.listener
MODIFY
package.json
package.json
},
"devDependencies": {
"@types/jest": "^22.2.3",
- "@types/supertest": "~2.0.4",
+ "@types/supertest": "^2.0.4",
"husky": "^0.14.3",
"jest": "^22.4.3",
"mock-req": "^0.2.0",
"nodemon": "^1.17.3",
"rimraf": "^2.6.2",
- "supertest": "~3.0.0",
+ "supertest": "^3.0.0",
"ts-jest": "~22.4.4",
"ts-node": "^6.0.2",
"tsc": "~1.20150623.0",

ADD
src/http.listener.spec.ts
+import { mapTo, tap } from 'rxjs/operators';
+import * as request from 'supertest';
+import { Effect } from './effects/effects.interface';
+import { httpListener } from './http.listener';
+import { matchPath } from './operators/matchPath.operator';
+
+describe('Http listener', () => {
+
+ it('reacts to attached effect', async () => {
+ const effect$: Effect = req$ => req$.pipe(
+ matchPath('/test'),
+ mapTo({ status: 200 })
+ );
+ const app = httpListener({ effects: [effect$] });
+
+ return request(app)
+ .get('/test')
+ .expect(200);
+ });
+
+ it('reacts to throwed exception', async () => {
+ const effect$: Effect = req$ => req$.pipe(
+ matchPath('/test'),
+ tap(() => { throw new Error(); }),
+ mapTo({ status: 200 })
+ );
+ const app = httpListener({ effects: [effect$] });
+
+ return request(app)
+ .get('/test')
+ .expect(500);
+ });
+
+});

test cases - http.listener