@@ -200,15 +200,38 @@ describe('Faker - matchMock', () => {
200200 response : { } ,
201201 delay : 0 ,
202202 } ,
203+ {
204+ url : 'http://request3.com?foo=1&bar=2' ,
205+ method : 'GET' ,
206+ status : 200 ,
207+ response : { } ,
208+ delay : 0 ,
209+ } ,
210+ {
211+ url : 'http://request4.com' ,
212+ method : 'GET' ,
213+ status : 200 ,
214+ response : { } ,
215+ delay : 0 ,
216+ ignoreQueryParams : true ,
217+ } ,
218+ {
219+ url : 'http://request5.com?foo=1&bar=2' ,
220+ method : 'GET' ,
221+ status : 200 ,
222+ response : { } ,
223+ delay : 0 ,
224+ ignoreQueryParams : true ,
225+ } ,
203226 ] ;
204227
205228 const [ faker , resetMock ] = setupMockFaker ( ) ;
206229
207- beforeAll ( ( ) => {
230+ beforeEach ( ( ) => {
208231 faker . makeInitialRequestMap ( requests ) ;
209232 } ) ;
210233
211- afterAll ( ( ) => {
234+ afterEach ( ( ) => {
212235 resetMock ( ) ;
213236 } ) ;
214237
@@ -230,6 +253,100 @@ describe('Faker - matchMock', () => {
230253 expect ( actual . method ) . toEqual ( requests [ 2 ] . method ) ;
231254 expect ( actual . skip ) . toEqual ( false ) ;
232255 } ) ;
256+
257+ it ( 'should return request if url and query parameters match' , ( ) => {
258+ const actual = faker . matchMock (
259+ 'http://request3.com?foo=1&bar=2' ,
260+ 'GET'
261+ ) ;
262+ expect ( actual . url ) . toEqual ( requests [ 3 ] . url ) ;
263+ expect ( actual . method ) . toEqual ( requests [ 3 ] . method ) ;
264+ expect ( actual . skip ) . toEqual ( false ) ;
265+ } ) ;
266+
267+ it ( 'should return request if url and query parameters match with different order' , ( ) => {
268+ const actual = faker . matchMock (
269+ 'http://request3.com?bar=2&foo=1' ,
270+ 'GET'
271+ ) ;
272+ expect ( actual . url ) . toEqual ( requests [ 3 ] . url ) ;
273+ expect ( actual . method ) . toEqual ( requests [ 3 ] . method ) ;
274+ expect ( actual . skip ) . toEqual ( false ) ;
275+ } ) ;
276+
277+ it ( 'should return null if unexpected query parameters are provided' , ( ) => {
278+ const actual = faker . matchMock ( 'http://request.com?foo=1' , 'GET' ) ;
279+ expect ( actual ) . toBeNull ( ) ;
280+ } ) ;
281+
282+ it ( 'should return null if query parameters are missing' , ( ) => {
283+ const actual = faker . matchMock ( 'http://request3.com?baz=1' , 'GET' ) ;
284+ expect ( actual ) . toBeNull ( ) ;
285+ } ) ;
286+
287+ it ( 'should return request if unexpected query parameters are provided but are globally ignored' , ( ) => {
288+ faker . setIgnoreQueryParams ( true ) ;
289+ const actual = faker . matchMock ( 'http://request.com?foo=1' , 'GET' ) ;
290+ expect ( actual . url ) . toEqual ( requests [ 0 ] . url ) ;
291+ expect ( actual . method ) . toEqual ( requests [ 0 ] . method ) ;
292+ expect ( actual . skip ) . toEqual ( false ) ;
293+ } ) ;
294+
295+ it ( 'should return request if query parameters are missing but are globally ignored' , ( ) => {
296+ faker . setIgnoreQueryParams ( true ) ;
297+ const actual = faker . matchMock ( 'http://request3.com?baz=1' , 'GET' ) ;
298+ expect ( actual . url ) . toEqual ( requests [ 3 ] . url ) ;
299+ expect ( actual . method ) . toEqual ( requests [ 3 ] . method ) ;
300+ expect ( actual . skip ) . toEqual ( false ) ;
301+ } ) ;
302+ } ) ;
303+
304+ describe ( 'Faker - matchQueryParams' , ( ) => {
305+ const [ faker , resetMock ] = setupMockFaker ( ) ;
306+
307+ afterEach ( ( ) => {
308+ resetMock ( ) ;
309+ } ) ;
310+
311+ it ( 'should return true if query parameters match' , ( ) => {
312+ const actual = faker . matchQueryParams (
313+ [ 'foo' , 'bar' ] ,
314+ [ 'foo' , 'bar' ] ,
315+ false
316+ ) ;
317+ expect ( actual ) . toBe ( true ) ;
318+ } ) ;
319+
320+ it ( 'should return true if query parameters match with different order' , ( ) => {
321+ const actual = faker . matchQueryParams (
322+ [ 'foo' , 'bar' ] ,
323+ [ 'bar' , 'foo' ] ,
324+ false
325+ ) ;
326+ expect ( actual ) . toBe ( true ) ;
327+ } ) ;
328+
329+ it ( 'should return false if unexpected query parameters are provided' , ( ) => {
330+ const actual = faker . matchQueryParams ( [ ] , [ 'foo' ] , false ) ;
331+ expect ( actual ) . toBe ( false ) ;
332+ } ) ;
333+
334+ it ( 'should return false if query parameters are missing' , ( ) => {
335+ const actual = faker . matchQueryParams ( [ 'foo' , 'bar' ] , [ 'baz' ] , false ) ;
336+ expect ( actual ) . toBe ( false ) ;
337+ } ) ;
338+
339+ it ( 'should return true if unexpected query parameters are provided but are globally ignored' , ( ) => {
340+ faker . setIgnoreQueryParams ( true ) ;
341+ const actual = faker . matchQueryParams ( [ ] , [ 'foo' ] , false ) ;
342+ expect ( actual ) . toBe ( true ) ;
343+ } ) ;
344+
345+ it ( 'should return true if query parameters are missing but are globally ignored' , ( ) => {
346+ faker . setIgnoreQueryParams ( true ) ;
347+ const actual = faker . matchQueryParams ( [ ] , [ 'foo' ] , false ) ;
348+ expect ( actual ) . toBe ( true ) ;
349+ } ) ;
233350} ) ;
234351
235352describe ( 'restore' , ( ) => {
0 commit comments