MockNativeBridge class
A mock NativeBridge for testing.
Records all sent commands and allows stubbing responses.
Example:
final mock = MockNativeBridge();
mock.stubResponse('window', 'create', 'window-123');
final host = PaletteHost.forTesting(bridge: mock);
// After some operations...
expect(mock.sentCommands, hasLength(1));
expect(mock.sentCommands.first.command, equals('create'));
- Implemented types
Constructors
Properties
- commandTimeout → Duration
-
Timeout for commands sent to native.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
sentCommands
→ List<
NativeCommand> -
All commands that have been sent.
final
-
stubbedResponses
→ Map<
String, dynamic> -
Stubbed responses keyed by 'service.command'.
final
Methods
-
callCount(
String service, String command) → int - Get count of commands sent to a service/command.
-
dispose(
) → void -
Dispose resources.
override
-
findCommands(
String service, String command) → List< NativeCommand> - Find commands by service and command name.
-
lastCommand(
String service) → NativeCommand? - Get the last command sent to a service.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onCommand(
void callback(NativeCommand)) → VoidCallback - Register a callback to be notified when any command is sent.
-
reset(
) → void - Clear all recorded commands and stubbed responses.
-
send<
T> (NativeCommand command) → Future< T?> -
Send a command to native.
override
-
sendFireAndForget(
NativeCommand command) → void -
Send a command, fire and forget (no result expected).
override
-
sendForMap(
NativeCommand command) → Future< Map< String, dynamic> ?> -
Send a command and expect a Map result.
override
-
simulateContentReady(
String windowId) → void - Simulate window content ready event.
-
simulateEvent(
NativeEvent event) → void - Simulate an event from native.
-
simulateEventDelayed(
NativeEvent event, {Duration delay = const Duration(milliseconds: 10)}) → Future< void> - Simulate an event after a delay (for async testing).
-
simulateHidden(
String windowId) → void - Simulate a visibility change event.
-
simulateShown(
String windowId) → void - Simulate a visibility change event.
-
stubDefaults(
) → void - Set up default stubs for common commands.
-
stubResponse(
String service, String command, dynamic response) → void - Stub a response for a service/command combination.
-
subscribe(
String service, NativeEventCallback callback) → void -
Subscribe to events from a specific service.
override
-
subscribeAll(
NativeEventCallback callback) → void -
Subscribe to all events (global listener).
override
-
toString(
) → String -
A string representation of this object.
inherited
-
unsubscribe(
String service, NativeEventCallback callback) → void -
Unsubscribe from events.
override
-
unsubscribeAll(
NativeEventCallback callback) → void -
Unsubscribe from all events.
override
-
wasCalled(
String service, String command) → bool - Check if a command was sent.
-
wasCalledFor(
String service, String command, String windowId) → bool - Check if a command was sent with specific window ID.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited