1- import HTTP , { HTTPComponent , HTTPMiddleware } from '..' ;
2- import * as express from '../__mocks__/express' ;
1+ import HTTP , { HTTPComponent , HTTPMiddleware , HTTPComponentInstance } from '..' ;
2+ import * as httpMock from '../__mocks__/http' ;
3+ import * as expressMock from '../__mocks__/express' ;
34
5+ jest . mock ( 'http' ) ;
46jest . mock ( 'express' ) ;
57
6- const { instance } = express ;
8+ const { instance : httpInstance } = httpMock ;
9+ const { instance : expressInstance } = expressMock ;
710
811describe ( 'HTTP' , ( ) => {
912 beforeEach ( ( ) => {
10- instance . get . mockReset ( ) ;
11- instance . put . mockReset ( ) ;
12- instance . post . mockReset ( ) ;
13- instance . delete . mockReset ( ) ;
13+ expressInstance . get . mockReset ( ) ;
14+ expressInstance . put . mockReset ( ) ;
15+ expressInstance . post . mockReset ( ) ;
16+ expressInstance . delete . mockReset ( ) ;
1417 } ) ;
1518
1619 describe ( '#constructor' , ( ) => {
@@ -27,7 +30,7 @@ describe('HTTP', () => {
2730
2831 expect ( http . app ) . not . toBeUndefined ( ) ;
2932
30- expect ( http . app ) . toBe ( instance ) ;
33+ expect ( http . app ) . toBe ( expressInstance ) ;
3134 } ) . not . toThrow ( ) ;
3235 } ) ;
3336 } ) ;
@@ -36,7 +39,7 @@ describe('HTTP', () => {
3639 test ( 'installs http components where path is a string' , ( ) => {
3740 const http = new HTTP ( ) ;
3841
39- const component : HTTPComponent = {
42+ const component : HTTPComponentInstance = {
4043 is : 'component' ,
4144 type : 'http' ,
4245 config : {
@@ -62,17 +65,19 @@ describe('HTTP', () => {
6265 http . http ( component ) ;
6366 } ) . not . toThrow ( ) ;
6467
65- expect ( instance . get . mock . calls . length ) . toBe ( 1 ) ;
66- expect ( instance . get . mock . calls [ 0 ] [ 0 ] ) . toBe (
68+ expect ( expressInstance . get . mock . calls . length ) . toBe ( 1 ) ;
69+ expect ( expressInstance . get . mock . calls [ 0 ] [ 0 ] ) . toBe (
6770 component . config . http . path ,
6871 ) ;
69- expect ( typeof instance . get . mock . calls [ 0 ] [ 1 ] ) . toBe ( 'function' ) ;
72+ expect ( typeof expressInstance . get . mock . calls [ 0 ] [ 1 ] ) . toBe (
73+ 'function' ,
74+ ) ;
7075 } ) ;
7176
7277 test ( 'installs http components where path is a regex' , ( ) => {
7378 const http = new HTTP ( ) ;
7479
75- const component : HTTPComponent = {
80+ const component : HTTPComponentInstance = {
7681 is : 'component' ,
7782 type : 'http' ,
7883 config : {
@@ -98,17 +103,19 @@ describe('HTTP', () => {
98103 http . http ( component ) ;
99104 } ) . not . toThrow ( ) ;
100105
101- expect ( instance . get . mock . calls . length ) . toBe ( 1 ) ;
102- expect ( instance . get . mock . calls [ 0 ] [ 0 ] ) . toBe (
106+ expect ( expressInstance . get . mock . calls . length ) . toBe ( 1 ) ;
107+ expect ( expressInstance . get . mock . calls [ 0 ] [ 0 ] ) . toBe (
103108 component . config . http . path ,
104109 ) ;
105- expect ( typeof instance . get . mock . calls [ 0 ] [ 1 ] ) . toBe ( 'function' ) ;
110+ expect ( typeof expressInstance . get . mock . calls [ 0 ] [ 1 ] ) . toBe (
111+ 'function' ,
112+ ) ;
106113 } ) ;
107114
108115 test ( 'installs http components where path is an array' , ( ) => {
109116 const http = new HTTP ( ) ;
110117
111- const component : HTTPComponent = {
118+ const component : HTTPComponentInstance = {
112119 is : 'component' ,
113120 type : 'http' ,
114121 config : {
@@ -137,11 +144,13 @@ describe('HTTP', () => {
137144 http . http ( component ) ;
138145 } ) . not . toThrow ( ) ;
139146
140- expect ( instance . get . mock . calls . length ) . toBe ( 1 ) ;
141- expect ( instance . get . mock . calls [ 0 ] [ 0 ] ) . toBe (
147+ expect ( expressInstance . get . mock . calls . length ) . toBe ( 1 ) ;
148+ expect ( expressInstance . get . mock . calls [ 0 ] [ 0 ] ) . toBe (
142149 component . config . http . path ,
143150 ) ;
144- expect ( typeof instance . get . mock . calls [ 0 ] [ 1 ] ) . toBe ( 'function' ) ;
151+ expect ( typeof expressInstance . get . mock . calls [ 0 ] [ 1 ] ) . toBe (
152+ 'function' ,
153+ ) ;
145154 } ) ;
146155
147156 test ( 'does not accept invalid components' , ( ) => {
@@ -353,9 +362,12 @@ describe('HTTP', () => {
353362 expect ( ( middleware . http as jest . Mock < { } > ) . mock . calls . length ) . toBe (
354363 1 ,
355364 ) ;
356- expect ( ( middleware . http as jest . Mock < { } > ) . mock . calls [ 0 ] [ 0 ] ) . toBe (
357- instance ,
358- ) ;
365+ expect (
366+ ( middleware . http as jest . Mock < { } > ) . mock . calls [ 0 ] [ 0 ] . app ,
367+ ) . toEqual ( expressInstance ) ;
368+ expect (
369+ ( middleware . http as jest . Mock < { } > ) . mock . calls [ 0 ] [ 0 ] . server ,
370+ ) . toBeTruthy ( ) ;
359371 } ) ;
360372
361373 test ( 'does not accept invalid http middleware' , ( ) => {
0 commit comments