# Mocktail

Use when creating mocks, stubbing methods, verifying interactions, registering fallback...

- Repository: https://github.com/evanca/flutter-ai-rules (668 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-10-30
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add evanca/flutter-ai-rules --skill mocktail -g -a claude-code -y`
Codex: `npx skills add evanca/flutter-ai-rules --skill mocktail -g -a codex -y`
Cursor: `npx skills add evanca/flutter-ai-rules --skill mocktail -g -a cursor -y`
Gemini CLI: `npx skills add evanca/flutter-ai-rules --skill mocktail -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add evanca/flutter-ai-rules`

## Description

Use when creating mocks, stubbing methods, verifying interactions, registering fallback values, or choosing between mocks, fakes, and real objects (Mocktail).

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# 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

The rest: https://github.com/evanca/flutter-ai-rules/blob/HEAD/skills/mocktail/SKILL.md
