-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coverage #3
Comments
Hi @pblinux! I'm glad to hear that you are enjoying the package! I've made a simple package with test_coverage and it works well with Please consider providing more information about the issue and environment you are working on. |
Hi @cah4a, thanks for the reply. Of course. Let me explain it: void main() {
setUpAll(() {
nock.defaultBase = "https://flusmic.cdn.prismic.io";
nock.init();
});
setUp(nock.cleanAll);
group('error from prismic', () {
test('bad request exception', () {
nock.get("/api/v2")..replay(400, 'data');
final flusmic =
Flusmic(prismicEndpoint: 'https://flusmic.cdn.prismic.io/api/v2');
expect(
() async => await flusmic.getApi(),
throwsA(
isA<FlusmicError>().having((e) => e.code, 'bad request', 400)));
});
});
}
Unhandled exception:
Tests failed with exit code 255
#0 runTestsAndCollect (package:test_coverage/src/functions.dart:120:5)
<asynchronous suspension>
#1 main (file:///home/pblinux/.pub-cache/hosted/pub.dartlang.org/test_coverage-0.4.1/bin/test_coverage.dart:51:9)
#2 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#3 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12) But when I remove this nock test file where I check errors,
Working with |
Hi @cah4a I've been doing tests and it's because of dio. Using http as client, everything works great. Maybe it will be useful to clarify that nock works better with |
Nock doesn't depend on We should investigate that. I hope I will have some time next week to reproduce your error. |
Hi @cah4a Yes, it's really weird because I just created a gist so we can do some tests over it: I'll be searching more about how Dio works, maybe do something in a different way. |
Finally got some time to investigate the issue. When you run That's why your tests work with What you can do now? Rewrite all the test cases as shown below: import 'dart:io';
import 'package:nock/src/overrides.dart';
void main() {
test('some test with nock', () async {
await HttpOverrides.runZoned(() {
nock("https://jsonplaceholder.cypress.io").get("/todos/1")
..replay(404, "result");
expect(() async => await get(), throwsException);
}, createHttpClient: (context) => MockClient());
})
} It's not very convenient cuz you have to repeat that pattern in every test, but it should work. I'm considering providing another initialization way for injecting nock. Maybe several ways. Have to think about it. Thanks again for reporting. |
Hi @cah4a Thank you very much, all is working now with Dio as client. I think isn't bad at all, just maybe a good idea would be clarify this in the readme to avoid future issues. Maybe a Test Coverage section would be useful since this a specific situation. Thanks again and if I can help with something, let me know. |
Your welcome! If you have other questions or suggestions, feel free to open an issue. |
@pblinux Could you share an example how you were able to Mock Dio requests using nock? |
Hi!
First, awesome work with nock, is so useful, thanks.
Everything is working great, but when I try to run tests with code coverage, fails. I have a couple of test files, one of those, use nock. To be more specific, the issue is when creating a single test file for group the coverage.
This is what I've tried so far:
pub run test
works without troubles.test_coverage
andtest_cov
packages fails.pub run test --coverage ./coverage
works but create a file for every test and I need a single one.pub run test test/main_test.dart --coverage ./coverage
works but only when no nock test included or nock test is alone.This is the
main_test.dart
file I'm using:The text was updated successfully, but these errors were encountered: