MockNetworkClient class

Mock implementation of INetworkClient for testing.

Use this to test your app without making real network requests:

final mockClient = MockNetworkClient();

// Set up mock responses
mockClient.mockResponse('getUsers', [
  {'id': 1, 'name': 'Test User'},
]);

// Initialize FKernal with mock
await FKernal.init(
  config: FKernalConfig(
    baseUrl: 'https://mock.api',
    networkClientOverride: mockClient,
  ),
  endpoints: endpoints,
);
Implemented types

Constructors

MockNetworkClient({String baseUrl = 'https://mock.api', Duration? latency})

Properties

baseUrl String
Base URL for the client.
final
hashCode int
The hash code for this object.
no setterinherited
latency Duration?
Artificial delay to simulate network latency.
getter/setter pair
requests List<MockRequest>
List of all requests made for verification.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

cancelAll() → void
Cancels all pending requests.
override
dispose() → void
Disposes the client.
override
getRequestsFor(String endpointId) List<MockRequest>
Gets all requests made to a specific endpoint.
mockError(String endpointId, Object error) → void
Sets up a mock error for an endpoint.
mockResponse<T>(String endpointId, T data) → void
Sets up a mock response for an endpoint.
mockStream<T>(String endpointId) StreamController<T>
Sets up a mock stream for an endpoint.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
request<T>(Endpoint endpoint, {Map<String, dynamic>? queryParams, Map<String, String>? pathParams, dynamic body}) Future<T>
Executes a request for a given endpoint.
override
reset() → void
Clears all mock responses and errors.
toString() String
A string representation of this object.
inherited
wasCalled(String endpointId) bool
Verifies that a specific endpoint was called.
watch<T>(Endpoint endpoint, {Map<String, dynamic>? queryParams, Map<String, String>? pathParams}) Stream<T>
Watches an endpoint for changes (Streams).
override

Operators

operator ==(Object other) bool
The equality operator.
inherited