mocktail
/mocktail
Use when creating mocks, stubbing methods, verifying interactions, registering fallback values, or choosing between mocks, fakes, and real objects (Mocktail).
- Author
- evanca ↗
- Repository
- flutter-ai-rules ↗
- Licence
- MIT
- Last repository change
- 10.10.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 1
No signals detected. Repository changed on 10.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Use when creating mocks, stubbing methods, verifying interactions, registering fallback values, or choosing between mocks, fakes, and real objects (Mocktail).
Original author description
Use when creating mocks, stubbing methods, verifying interactions, registering fallback values, or choosing between mocks, fakes, and real objects (Mocktail).
How it works
- 1. Mock vs. Fake vs. Real Object
- 2. Creating Mocks
- 3. Registering Fallback Values
- 4. Stubbing
- 5. Named Parameters
- 6. Verification
- 7. Argument Matchers
- References
SKILL.md preview
---
name: mocktail
description: "Use when creating mocks, stubbing methods, verifying interactions, registering fallback values, or choosing between mocks, fakes, and real objects (Mocktail)."
license: MIT
---
# Mocktail Skill
This skill defines how to correctly use the `mocktail` package for mocking in Dart and Flutter tests.
---
## 1. Mock vs. Fake vs. Real Object
| Use | When |
|---|---|
| **Real object** | Prefer over mocks when practical. |
| **Fake** (`extends Fake`) | Lightweight custom implementation; override only the methods you need. Prefer over mocks when you don't need interaction verification. |
| **Mock** (`extends Mock`) | Only when you need to **verify interactions** (call counts, arguments) or stub dynamic responses. |
- Never add `@override` methods or implementations to a class extending `Mock`.
- Only use mocks if your test has `verify` assertions; otherwise prefer real or fake objects.
---
## 2. Creating Mocks
```dart
class MockMyService extends Mock implements MyService {}
class FakeMyEvent extends Fake implements MyEvent {}
```
No code generation required — unlike Mockito, Mocktail uses `noSuchMethod` at runtime.
---
## 3. Registering Fallback Values
Register fallback values **before** using custom types with argument matchers. Do this in `setUpAll` or at the top of your test:
```dart
setUpAll(() {
registerFallbackValue(FakeMyEvent());
});
```
- Required for non-nullable custom types used with `any()`, `captureAny()`, or `captureThat()`.
- Register fallback values for **any** custom type used with argument matchers.
---
## 4. Stubbing
```dart
final mock = MockMyService();
// Return a value
when(() => mock.fetchData()).thenReturn('result');
// Throw an error
when(() => mock.fetchData()).thenThrow(Exception('error'));
// Dynamic/async response
when(() => mock.fetchData()).thenAnswer((_) async => 'result');
// Future<void>
when(() => mock.doWork()).thenAnswer((_) async {});
```
- Always stub async methods (returning `Future` or `Future<void>`) with `thenAnswer`.
- Stub every method you expect to be called, even if it's not the focus of your test.
---
## 5. Named Parameters
Always include **all named parameters** in both `when` and `verify` calls. Use `any(named: 'paramName')` for those you don't care about:
```dart
when(() => mock.fetch(
id: any(named: 'id'),
headers: any(named: 'headers'),
)).thenReturn(response);
```
- If a method has default values for named parameters, Mocktail still expects them all to be matched.
---
## 6. Verification
```dart
verify(() => mock.fetchData()); // called at least once
verifyNever(() => mock.fetchData()); // never called
verify(() => mock.fetchData()).called(2); // called exactly twice
```
---
## 7. Argument Matchers
```dart
// Any positional argument
when(() => mock.process(any())).thenReturn(true);
// Capture arguments for later assertions
final captured = verify(() => mock.process(captureAny())).captured;
print(captured.last);
```
- Use `any()` for positional parameters when you don't care about the exact value.
- Use `captureThat()` for conditional capturing.
- When matching string output, be aware of what `.toString()` returns for the type.
---
## References
- [Mocktail GitHub Repository](https://github.com/felangel/mocktail)
Versions
The database has no other skills named mocktail.
Identical content appears in 1 other GitHub folders. We show one copy with the highest score.
Database snapshot: 13.11.2026 · package version 1e46ab913678 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 1 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100mockito
Use when generating mocks, stubbing methods, verifying interactions, capturing arguments, or choosing between mocks, fakes, and real objects (Mockito). - 100dart-generate-test-mocks
Use when generating mock objects with package:mockito and build_runner, or choosing between mocktail and mockito. - 100flutter-testing
Write, fix, review, debug, and validate Flutter tests for apps, packages, and plugins. Use when adding unit tests, widget tests, integration tests, MethodChannel or plugin mocks, Mockito or mocktail test doubles, golden or accessibility checks, CI test commands, test failures,… - 100testing
Best practices for Dart unit tests, Flutter widget tests, and golden file tests, covering group and test naming, setUp lifecycle and isolation, mocking with package:mocktail, and the shared pumpApp helper. Use when writing, modifying, or reviewing tests, goldens included, that… - 100flutter-testing
Use when writing or fixing Flutter tests, including unit tests, widget tests with testWidgets, golden tests, integration_test, and mocks. Triggers on "write tests for", "flutter test", "testWidgets", "golden test", "mocktail", "pumpAndSettle timed out". - 100multiple-add
Generate vexana models, services, fake services, mocktail service tests and model tests for several JSON samples at once (a folder, several files or a pasted list), deduplicating shared nested types. Use when the user says "vexana multiple add", "bu JSON'ların hepsini ekle",…