nock 1.2.3 copy "nock: ^1.2.3" to clipboard
nock: ^1.2.3 copied to clipboard

HTTP requests mocking library for dart and flutter. Test your application in isolation.

example/main.dart

import 'package:test/test.dart';
import 'package:http/http.dart' as http;
import 'package:nock/nock.dart';

void main() {
  setUpAll(() {
    nock.init();
  });

  setUp(() {
    nock.cleanAll();
  });

  test('example', () async {
    final interceptor = nock('http://localhost/api').get('/users')
      ..reply(
        200,
        'result',
      );

    final response = await http.get(Uri.parse('http://localhost/api/users'));

    expect(interceptor.isDone, true);
    expect(response.statusCode, 200);
    expect(response.body, 'result');
  });
}
23
likes
130
pub points
85%
popularity

Publisher

unverified uploader

HTTP requests mocking library for dart and flutter. Test your application in isolation.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

collection, test

More

Packages that depend on nock