GisilaTestClient class
Sends requests straight into an app's handler.
final client = GisilaTestClient(app);
final res = await client.withToken(token).post('/notes', json: {'title': 'a'});
expect(res.statusCode, 201);
expect(res.jsonMap['title'], 'a');
Clients are immutable: withToken, withHeaders and as return a new one, so a shared base client can't leak credentials between tests.
Constructors
-
GisilaTestClient(GisilaApp app, {Map<
String, String> headers = const {}, Uri? baseUri}) - Builds the app's handler once. Register controllers and services before creating the client.
-
GisilaTestClient.handler(Handler handler, {Map<
String, String> headers = const {}, Uri? baseUri}) -
A client for any Shelf
handler(a router mounted without GisilaApp, say). as is not available.
Properties
- baseUri → Uri
-
Scheme and host requests are addressed to.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
headers
→ Map<
String, String> -
Headers sent with every request; per-request
headerswin.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
as(
Principal principal) → GisilaTestClient -
A client authenticated as
principal. The app's authenticator must be a TestAuthenticator. -
delete(
String path, {Object? json, Map< String, Object?> ? query, Map<String, String> ? headers}) → Future<TestResponse> -
get(
String path, {Map< String, Object?> ? query, Map<String, String> ? headers}) → Future<TestResponse> -
head(
String path, {Map< String, Object?> ? query, Map<String, String> ? headers}) → Future<TestResponse> -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
options(
String path, {Map< String, Object?> ? query, Map<String, String> ? headers}) → Future<TestResponse> -
patch(
String path, {Object? json, Map< String, String> ? form, Object? body, String? contentType, Map<String, Object?> ? query, Map<String, String> ? headers}) → Future<TestResponse> -
post(
String path, {Object? json, Map< String, String> ? form, Object? body, String? contentType, Map<String, Object?> ? query, Map<String, String> ? headers}) → Future<TestResponse> -
put(
String path, {Object? json, Map< String, String> ? form, Object? body, String? contentType, Map<String, Object?> ? query, Map<String, String> ? headers}) → Future<TestResponse> -
request(
String method, String path, {Object? json, Map< String, String> ? form, Object? body, String? contentType, Map<String, Object?> ? query, Map<String, String> ? headers}) → Future<TestResponse> -
Sends one request. Give at most one body:
json(encoded, withapplication/json),form(url-encoded), or a rawbody(Stringor bytes) with itscontentType.queryvalues may be lists for repeated keys. -
toString(
) → String -
A string representation of this object.
inherited
-
withHeaders(
Map< String, String> extra) → GisilaTestClient -
A client that also sends
extra. -
withToken(
String token) → GisilaTestClient -
A client that sends
Authorization: Bearer <token>.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited