C3Http.Mock
Inherits: RefCounted
Test helper that intercepts request() calls. Install with install(), configure canned responses with stub(), and inspect recorded calls via calls. Always pair install() with uninstall() in after_each().
var mock: C3Http.Mock
func before_each() -> void:
mock = C3Http.Mock.new()
mock.install()
func after_each() -> void:
mock.uninstall()
func test_example() -> void:
mock.stub().ok({"id": 1})
var res := await C3Http.request("https://api.example.com/users")
assert_true(res.ok)
assert_eq(mock.last_call["url"], "https://api.example.com/users")
Properties
| Type | Name | Default |
|---|---|---|
Array[Dictionary] |
calls |
[] |
int |
call_count |
|
Dictionary |
last_call |
Methods
| Returns | Signature |
|---|---|
void |
install() |
void |
uninstall() |
C3Http._Stub |
stub(url: String = "") |
void |
reset() |
C3Http.Response |
request(url: String, custom_headers: PackedStringArray, method: int, request_data: Variant, options: C3Http.Options, _redirects_left: int = -1, _on_worker: bool = false, _start_ms: int = -1, _force_fresh: bool = false) |
Property Descriptions
Array[Dictionary] calls = []
Recorded calls in order, newest last. Each entry is a Dictionary with keys url (String), method (int, HTTPClient.METHOD_*), headers (PackedStringArray), body (Variant), and options (C3Http.Options).
int call_count
Total number of calls received since construction or the last reset().
Dictionary last_call
The most recent call dictionary, or an empty Dictionary if no calls have been made yet.
Method Descriptions
install
func install() -> void:
Installs this mock as C3Http._impl.
uninstall
func uninstall() -> void:
Uninstalls this mock and restores normal request behavior.
stub
func stub(url: String = "") -> C3Http._Stub:
Returns a stub builder for url. Omit url to create the catch-all default stub, matched when no URL-specific stub exists.
Stubs are evaluated in registration order; the first exact URL match wins, then the first default stub, then an empty C3Http.Response.
reset
func reset() -> void:
Clears all recorded calls and registered stubs.
request
func request(
url: String,
custom_headers: PackedStringArray,
method: int,
request_data: Variant,
options: C3Http.Options,
_redirects_left: int = -1,
_on_worker: bool = false,
_start_ms: int = -1,
_force_fresh: bool = false
) -> C3Http.Response: