@@ -35,12 +35,30 @@ it("falls through to global fetch() if unmatched", async () => {
3535it ( "intercepts URLs with query parameters with repeated keys" , async ( ) => {
3636 fetchMock
3737 . get ( "https://example.com" )
38- . intercept ( { path : "/foo/bar?a=1&a=2" } )
39- . reply ( 200 , "body " ) ;
38+ . intercept ( { path : "/foo" , query : { key : "value" } } )
39+ . reply ( 200 , "foo " ) ;
4040
41- let response = await fetch ( "https://example.com/foo/bar?a=1&a=2" ) ;
42- expect ( response . url ) . toEqual ( "https://example.com/foo/bar?a=1&a=2" ) ;
43- expect ( await response . text ( ) ) . toBe ( "body" ) ;
41+ fetchMock
42+ . get ( "https://example.com" )
43+ . intercept ( { path : "/bar?a=1&a=2" } )
44+ . reply ( 200 , "bar" ) ;
45+
46+ fetchMock
47+ . get ( "https://example.com" )
48+ . intercept ( { path : "/baz" , query : { key1 : [ "a" , "b" ] , key2 : "c" } } )
49+ . reply ( 200 , "baz" ) ;
50+
51+ let response1 = await fetch ( "https://example.com/foo?key=value" ) ;
52+ expect ( response1 . url ) . toEqual ( "https://example.com/foo?key=value" ) ;
53+ expect ( await response1 . text ( ) ) . toBe ( "foo" ) ;
54+
55+ let response2 = await fetch ( "https://example.com/bar?a=1&a=2" ) ;
56+ expect ( response2 . url ) . toEqual ( "https://example.com/bar?a=1&a=2" ) ;
57+ expect ( await response2 . text ( ) ) . toBe ( "bar" ) ;
58+
59+ let response3 = await fetch ( "https://example.com/baz?key1=a&key2=c&key1=b" ) ;
60+ expect ( response3 . url ) . toEqual ( "https://example.com/baz?key1=a&key2=c&key1=b" ) ;
61+ expect ( await response3 . text ( ) ) . toBe ( "baz" ) ;
4462} ) ;
4563
4664describe ( "AbortSignal" , ( ) => {
0 commit comments