Function When_I_intercept_URL

  • When I intercept URL:

    When I intercept URL {string}
    

    Stub network requests and responses.

    Parameters

    • url: string
    • OptionalrouteMatcher: DataTable

    Returns void

    Intercept HTTP request and stub response body:

    When I intercept URL "/api/users/1"
    | body | {"name":"Mark"} |

    With routeMatcher options:

    When I intercept URL "/api/users/1"
    | auth | {"username":"user","password":"pass"} |
    | body | {"name":"Mark"} |
    | headers | {"X-Requested-With":"exampleClient"} |
    | hostname | localhost |
    | https | true |
    | method | GET |
    | middleware | false |
    | path | /api/commands/intercept?foo=bar |
    | pathname | /api/commands/intercept |
    | port | 8080 |
    | query | {"foo":"bar"} |
    | resourceType | fetch |
    | times | 1 |

    routeMatcher options:

    Option Description
    auth HTTP Basic Authentication (object with keys username and password)
    body HTTP response body (object or string)
    headers HTTP request headers (object)
    hostname HTTP request hostname
    https true: only secure (https://) requests, false: only insecure (http://) requests
    method HTTP request method (matches any method by default)
    middleware true: match route first and in defined order, false: match route in reverse order (default)
    path HTTP request path after the hostname, including query parameters
    pathname Like path, but without query parameters
    port HTTP request port(s) (number or Array)
    query Parsed query string (object)
    resourceType The resource type of the request. See "Request object properties" for a list of possible values for resourceType.
    times Maximum number of times to match (number)

    All intercepts are automatically cleared before every test.