daravel_test 1.6.0
daravel_test: ^1.6.0 copied to clipboard
Testing toolkit for Daravel applications (TestClient, assertions, database helpers, fakes, time travel, architecture checks).
daravel_test #
Testing toolkit for Daravel applications, in the spirit of Laravel's testing helpers.
dart pub add dev:daravel_test
import 'package:daravel_test/daravel_test.dart';
import 'package:test/test.dart';
void main() {
final db = refreshDatabase(createApp); // each test rolls back
test('creates a post', () async {
final client = TestClient(db.app).actingAs(await UserFactory().create());
(await client.post('/api/posts', json: {'title': 'Hello'}))
.assertCreated()
.assertJsonPath('data.title', 'Hello');
await assertDatabaseHas('posts', {'title': 'Hello'});
});
}
TestClientwithactingAs,withToken,withHeaders,withoutExceptionHandling, and fluentTestResponseassertions.refreshDatabase,assertDatabaseHas/Missing/Count.- Time travel (
freezeTime,travel,travelTo) over Daravel'sClock. - Architecture checks (
expectRegistryComplete) and lint integration. package:daravel_test/conformance.dart: Laravel 12 wire-format contracts (isLaravelValidationError,isLaravelErrorBody,isLaravelLengthAwarePaginator, Sanctum token format, ...) to prove your API still speaks Laravel.
See example/main.dart and the
testing guide.
License and trademarks #
MIT. "Laravel" is a trademark of Laravel Holdings Inc.; "Dart" is a trademark of Google LLC. Daravel is an independent project, not affiliated with or endorsed by either.