Questions tagged [dart-mock]
7 questions
12
votes
3 answers
How can make a matcher for a string containing a substring, while ignoring case
I'm writing a unit test using mockito to mock a dependency and check we're calling it with the right argument. We should be passing in a string, so I'm trying to match on that function argument, but without asserting on the whole string, in case we…

Jezzamon
- 1,453
- 1
- 15
- 27
6
votes
4 answers
Mocking HTTP response with Dart
I have been working on a new API wrapper and don't want to be calling the API every time my unit tests run. So as described here, I'm mocking it.
I initially thought there was something wrong with the way I'm mocking it, but it seems the problem is…

Marcos Placona
- 21,468
- 11
- 68
- 93
4
votes
2 answers
Mock http.Client in Dart gives exception
I have a problem when testing my classes that make http requests.
I want to Mock the client so that every time the client makes a request, I can answer with a Mocked response.
At the moment my code looks like this:
final fn = MockClientHandler;
…

Merdan Durmus
- 65
- 4
1
vote
1 answer
How to return this crazy type in Dart?
I am trying to mock the .find function in mongo_dart and it is asking for a return function that I just can't work out. It has a type, then another type, then the name. What / how do I express this return type.
This is legitimate code…

Ryan Knell
- 6,204
- 2
- 40
- 32
1
vote
0 answers
Flutter Stubbing : use Stub method's return value property
Hi this is the method i want to stub : the checkLimit method.
class MyClass {
final ResponseBase isAvailable =
await sampleRepository.checkLimit(data: _data);
if (isAvailable.status == ResponseStatus.notOk) {
yield…

Benedicto Jr Nicolas
- 11
- 1
1
vote
1 answer
Mocking with Dart
I've been trying to get my head around the mocking library in dart, but it seems I've still not got it.
In my library, I have an HTTP request to an external resource, which I would like to mock as to not rely on the external resource all the…

Marcos Placona
- 21,468
- 11
- 68
- 93
0
votes
1 answer
how do I unit test with multiple expect
The unit test I write below doesn't work when there are 3 expect, how can I rewrite the unit test below:
test('400 bad response', () async {
when(
() => sampleClient.getTransaction(
'1'),
).thenThrow(DioError(
response:…

Alvin
- 8,219
- 25
- 96
- 177