testing/testing library
Testing utilities for Chase framework.
Provides mock implementations and helpers for testing Chase applications.
Automatically suppresses framework logs during tests to keep output clean.
Example:
import 'package:chase/testing/testing.dart';
void main() {
test('handles GET request', () async {
final ctx = TestContext.get('/users?page=1');
await myHandler(ctx);
expect(ctx.response.statusCode, 200);
expect(ctx.response.body, contains('users'));
});
}
Classes
- AuthHelper
- Helpers for authentication in tests.
- MockHttpConnectionInfo
- Mock implementation of HttpConnectionInfo for testing.
- MockHttpHeaders
- Mock implementation of HttpHeaders for testing.
- MockHttpRequest
- Mock implementation of HttpRequest for testing.
- MockHttpResponse
- Mock implementation of HttpResponse for testing.
- MockInternetAddress
- Mock implementation of InternetAddress for testing.
- MultipartFileData
- Data for a multipart file upload in tests.
- RequestHelper
- Helpers for building test requests.
- ResponseExpect
- Fluent assertion builder for TestResponse.
- TestClient
- HTTP client for testing Chase applications.
- TestContext
- Factory for creating test Context instances.
- TestResponse
- Response wrapper for testing assertions.
Extensions
- CookieTestingExtension on TestResponse
- Extension on TestResponse for cookie testing.
- FluentAssertions on TestResponse
- Extension on TestResponse for fluent assertions.
- TestClientExtensions on TestClient
- Extension on TestClient for common patterns.
- TestContextExtension on Context
- Extension to easily access mock response from Context.
Constants
- isClientErrorResponse → const Matcher
- Matches a response with status code in the 4xx range.
- isOkResponse → const Matcher
- Matches a response with status code in the 2xx range.
- isRedirectResponse → const Matcher
- Matches a response with status code in the 3xx range.
- isServerErrorResponse → const Matcher
- Matches a response with status code in the 5xx range.
Functions
-
buildMiddlewareChain(
List< Middleware> middlewares, Handler finalHandler) → Handler - Builds a handler chain from middlewares.
-
hasContentType(
String type) → Matcher - Matches a response with Content-Type containing the given type.
-
hasCookie(
String name, [Object? valueMatcher]) → Matcher - Matches a response that has a Set-Cookie header with the given name.
-
hasHeader(
String name, [Object? valueMatcher]) → Matcher - Matches a response that has the specified header.
-
hasJsonPath(
String path, Object? valueMatcher) → Matcher - Matches a response body against the given matcher.
-
hasStatus(
int statusCode) → Matcher - Matches a response with the exact status code.
-
runMiddleware(
Middleware middleware, Context ctx, Future< void> next()) → Future<void> - Runs a single middleware and handles Response returns.
-
suppressTestLogs(
) → void - Suppresses all framework logs during tests.
Exceptions / Errors
- ChaseTestFailure
- Exception thrown when a test assertion fails.