Open eseidel opened 11 months ago
This was the other bug I thought I had, but can't seem to repro now:
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
class One {
final Two two = Two();
}
class Two {
String three(String arg) => arg;
}
class _MockOne extends Mock implements One {}
class _MockTwo extends Mock implements Two {}
void main() {
test('nested mocks', () {
final one = _MockOne();
final two = _MockTwo();
when(() => one.two).thenReturn(two);
when(() => two.three('three')).thenReturn('three');
one.two.three('three');
one.two.three('three');
verify(() => one.two.three('three')).called(2);
});
}
Where call counts would get double-counted when using nested mocks in the verify() call.
This was the other bug I thought I had, but can't seem to repro now:
import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; class One { final Two two = Two(); } class Two { String three(String arg) => arg; } class _MockOne extends Mock implements One {} class _MockTwo extends Mock implements Two {} void main() { test('nested mocks', () { final one = _MockOne(); final two = _MockTwo(); when(() => one.two).thenReturn(two); when(() => two.three('three')).thenReturn('three'); one.two.three('three'); one.two.three('three'); verify(() => one.two.three('three')).called(2); }); }
Where call counts would get double-counted when using nested mocks in the verify() call.
Hmm let me know if you find a way to reproduce it and I’ll check it out 👀
I suspect I have the curse of knowledge now and just know to avoid these things. :) Thanks!
I had a test succeed when it shouldn't have, I think due to this issue. To reproduce:
code (abbreviated for clarity):
final deleteReleaseQuery = // the query;
final deleteReleaseResponse = await bigqueryClient.query(deleteReleaseQuery);
final deletePatchesQuery = '''
lkajsdfjasdkfjklasdfjklsdajfklasdjklasdfjklasdjf''';
final deletePatchesResponse =
await bigqueryClient.query(deletePatchesQuery);
test:
when(() => bigqueryClient.projectId).thenReturn('test-project-id');
verifyInOrder([
() => bigqueryClient.query('''
DELETE `${bigqueryClient.projectId}.command_metadata.release`
WHERE id = ${release.id};'''),
() => bigqueryClient.query(
'''
DELETE `${bigqueryClient.projectId}.command_metadata.patch`
WHERE id in (11);''',
),
]);
This test succeeded because I was referencing the mocked bigqueryClient.projectId
in verifyInOrder
.
Thanks @bryanoltman!
Also seems related to https://github.com/felangel/mocktail/issues/179
I meant to file this a few weeks ago, sorry.
That's a better error than I remember (I remember it being silent?) But it's still pretty confusing. Feel free to close.