Skip to main content

daravel_test 1.9.0 copy "daravel_test: ^1.9.0" to clipboard
daravel_test: ^1.9.0 copied to clipboard

Testing toolkit for Daravel applications (TestClient, assertions, database helpers, fakes, time travel, architecture checks).

example/main.dart

import 'dart:io';

import 'package:daravel/daravel.dart';
import 'package:daravel_test/conformance.dart';
import 'package:daravel_test/daravel_test.dart';
import 'package:test/test.dart';

Application createApp() =>
    Application.configure(basePath: Directory.systemTemp.path)
        .withEnv(const {'APP_ENV': 'testing', 'DB_DATABASE': ':memory:'})
        .withRouting(
          apiPrefix: '/api',
          api: (router) {
            router.get('/ping', (_) => {'ok': true});
            router.post('/users', (request) async {
              final data = await request.validate({'email': 'required|email'});
              return Response.created(data.toMap());
            });
          },
        )
        .create();

/// Feature tests with `TestClient` and Laravel conformance matchers.
/// Run with `dart test example/main.dart`.
void main() {
  late Application app;
  late TestClient client;

  setUp(() async {
    app = createApp();
    await app.boot();
    client = TestClient(app);
  });
  tearDown(() => app.shutdown());

  test('ping', () async {
    (await client.get('/api/ping')).assertOk().assertExactJson({'ok': true});
  });

  test('validation errors use Laravel 422 bodies', () async {
    final response = await client.post('/api/users', json: {'email': 'nope'});
    response.assertUnprocessable();
    expect(
      response.json,
      isLaravelValidationError({
        'email': ['The email field must be a valid email address.'],
      }),
    );
  });
}
0
likes
160
points
0
downloads

Documentation

Documentation
API reference

Publisher

verified publisherdaravel.teoprayoga.my.id

Weekly Downloads

Testing toolkit for Daravel applications (TestClient, assertions, database helpers, fakes, time travel, architecture checks).

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#testing #server #http #backend #database

License

MIT (license)

Dependencies

collection, daravel, daravel_lints, path, test

More

Packages that depend on daravel_test