NetworkMocker

public struct NetworkMocker

Can be used for registering Mocked data, returned by the MockingURLProtocol.

  • Undocumented

    See more

    Declaration

    Swift

    public enum HTTPVersion : String
  • The way Mocker handles unregistered urls

    See more

    Declaration

    Swift

    public enum Mode
  • The mode defines how unknown URLs are handled. Defaults to optout which means requests without a mock will fail.

    Declaration

    Swift

    public static var mode: Mode
  • The HTTP Version to use in the mocked response.

    Declaration

    Swift

    public static var httpVersion: HTTPVersion
  • URLs to ignore for mocking.

    Declaration

    Swift

    public var ignoredURLs: [URL] { get }
  • Register new Mocked data. If a mock for the same URL and HTTPMethod exists, it will be overwritten.

    Declaration

    Swift

    public static func register(_ mock: NetworkMock)

    Parameters

    mock

    The Mock to be registered for future requests.

  • Register an URL to ignore for mocking. This will let the URL work as if the Mocker doesn’t exist.

    Declaration

    Swift

    public static func ignore(_ url: URL, ignoreQuery: Bool = false)

    Parameters

    url

    The URL to mock.

    ignoreQuery

    If true, checking the URL will ignore the query and match only for the scheme, host and path. Defaults to false.

  • Checks if the passed URL should be handled by the Mocker. If the URL is registered to be ignored, it will not handle the URL.

    Declaration

    Swift

    public static func shouldHandle(_ request: URLRequest) -> Bool

    Parameters

    url

    The URL to check for.

    Return Value

    true if it should be mocked, false if the URL is registered as ignored.

  • Removes all registered mocks. Use this method in your tearDown function to make sure a Mock is not used in any other test.

    Declaration

    Swift

    public static func removeAll()