@@ -34,7 +34,7 @@ describe('HTTP', () => {
34
34
} ) ;
35
35
36
36
describe ( '#http' , ( ) => {
37
- test ( 'installs http components' , ( ) => {
37
+ test ( 'installs http components where path is a string ' , ( ) => {
38
38
const http = new HTTP ( ) ;
39
39
40
40
const component : HTTPComponent = {
@@ -70,6 +70,81 @@ describe('HTTP', () => {
70
70
expect ( typeof instance . get . mock . calls [ 0 ] [ 1 ] ) . toBe ( 'function' ) ;
71
71
} ) ;
72
72
73
+ test ( 'installs http components where path is a regex' , ( ) => {
74
+ const http = new HTTP ( ) ;
75
+
76
+ const component : HTTPComponent = {
77
+ is : 'component' ,
78
+ config : {
79
+ type : 'http' ,
80
+ http : {
81
+ path : / \/ / ,
82
+ method : 'get' ,
83
+ } ,
84
+ dependencies : {
85
+ plugins : [
86
+ 'http' ,
87
+ ] ,
88
+ services : [ ] ,
89
+ } ,
90
+ } ,
91
+ http : jest . fn ( ) ,
92
+ plugins : [
93
+ http ,
94
+ ] as any ,
95
+ services : [ ] as any ,
96
+ } ;
97
+
98
+ expect ( ( ) => {
99
+ http . http ( component ) ;
100
+ } ) . not . toThrow ( ) ;
101
+
102
+ expect ( instance . get . mock . calls . length ) . toBe ( 1 ) ;
103
+ expect ( instance . get . mock . calls [ 0 ] [ 0 ] ) . toBe (
104
+ component . config . http . path ,
105
+ ) ;
106
+ expect ( typeof instance . get . mock . calls [ 0 ] [ 1 ] ) . toBe ( 'function' ) ;
107
+ } ) ;
108
+
109
+ test ( 'installs http components where path is an array' , ( ) => {
110
+ const http = new HTTP ( ) ;
111
+
112
+ const component : HTTPComponent = {
113
+ is : 'component' ,
114
+ config : {
115
+ type : 'http' ,
116
+ http : {
117
+ path : [
118
+ '/' ,
119
+ / x / ,
120
+ ] ,
121
+ method : 'get' ,
122
+ } ,
123
+ dependencies : {
124
+ plugins : [
125
+ 'http' ,
126
+ ] ,
127
+ services : [ ] ,
128
+ } ,
129
+ } ,
130
+ http : jest . fn ( ) ,
131
+ plugins : [
132
+ http ,
133
+ ] as any ,
134
+ services : [ ] as any ,
135
+ } ;
136
+
137
+ expect ( ( ) => {
138
+ http . http ( component ) ;
139
+ } ) . not . toThrow ( ) ;
140
+
141
+ expect ( instance . get . mock . calls . length ) . toBe ( 1 ) ;
142
+ expect ( instance . get . mock . calls [ 0 ] [ 0 ] ) . toBe (
143
+ component . config . http . path ,
144
+ ) ;
145
+ expect ( typeof instance . get . mock . calls [ 0 ] [ 1 ] ) . toBe ( 'function' ) ;
146
+ } ) ;
147
+
73
148
test ( 'does not accept invalid components' , ( ) => {
74
149
const http = new HTTP ( ) ;
75
150
0 commit comments