重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
dart-matcher-best-practices by kevmoo/dash_skills
npx skills add https://github.com/kevmoo/dash_skills --skill dart-matcher-best-practices在以下情况下使用此技能:
expect 和 package:matcher 编写断言时。hasLength, contains, isEmpty)hasLength(n):
expect(list, hasLength(n)) 而非 expect(list.length, n)。广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
isEmpty / isNotEmpty:
expect(list, isEmpty) 而非 expect(list.isEmpty, true)。expect(list, isNotEmpty) 而非 expect(list.isNotEmpty, true)。contains(item):
unorderedEquals(items):
isA<T> 和 TypeMatcher<T>)isA<T>():
expect(obj, isA<Type>())。TypeMatcher<Type>() 更简洁易读。.having() 链接约束条件。TypeMatcher<T>:
const:const isMyType = TypeMatcher<MyType>();.having() 也有效,但生成的匹配器不是 const。having)在 isA<T>() 或其他 TypeMatchers 上使用 .having() 来检查属性。
描述性名称:在闭包中使用有意义的参数名(例如 (e) => e.message),而不是像 p0 这样的通用名称,以提高可读性。
expect(person, isA<Person>()
.having((p) => p.name, 'name', 'Alice')
.having((p) => p.age, 'age', greaterThan(18)));
这会提供详细的失败信息,明确指出哪个属性未通过检查。
completion(matcher):
await expectLater(...) 以确保 Future 在测试继续之前完成。await expectLater(future, completion(equals(42)))。throwsA(matcher):
await expectLater(future, throwsA(isA<StateError>()))。expect(() => function(), throwsA(isA<ArgumentError>()))(同步函数抛出异常时,使用 expect 即可)。expectLater在测试异步行为时使用 await expectLater(...),以确保正确的执行顺序。
// 良好:在检查副作用之前等待 Future 完成
await expectLater(future, completion(equals(42)));
expect(sideEffectState, equals('done'));
// 不佳:副作用检查可能在 Future 完成之前运行
expect(future, completion(equals(42)));
expect(sideEffectState, equals('done')); // 竞态条件!
if 语句或 for 循环进行断言;让匹配器来处理。containsPair 而不是手动检查键)。dart-test-fundamentals:关于测试结构、生命周期和配置的核心概念。dart-checks-migration:如果你正在将测试从 package:matcher 迁移到现代的 package:checks,请使用此技能。每周安装次数
61
代码仓库
GitHub 星标数
120
首次出现
2026年2月16日
安全审计
安装于
antigravity45
github-copilot27
codex26
opencode25
gemini-cli25
cursor25
Use this skill when:
expect and package:matcher.hasLength, contains, isEmpty)hasLength(n) :
expect(list, hasLength(n)) over expect(list.length, n).isEmpty / isNotEmpty:
expect(list, isEmpty) over expect(list.isEmpty, true).expect(list, isNotEmpty) over expect(list.isNotEmpty, true).contains(item) :
unorderedEquals(items) :
isA<T> and TypeMatcher<T>)isA<T>():
expect(obj, isA<Type>()).TypeMatcher<Type>()..having().TypeMatcher<T>:
const: const isMyType = TypeMatcher<MyType>();.having() works here too, but the resulting matcher is not .having)Use .having() on isA<T>() or other TypeMatchers to check properties.
Descriptive Names : Use meaningful parameter names in the closure (e.g., (e) => e.message) instead of generic ones like p0 to improve readability.
expect(person, isA<Person>() .having((p) => p.name, 'name', 'Alice') .having((p) => p.age, 'age', greaterThan(18)));
This provides detailed failure messages indicating exactly which property failed.
completion(matcher) :
await expectLater(...) to ensure the future completes before the test continues.await expectLater(future, completion(equals(42))).throwsA(matcher) :
await expectLater(future, throwsA(isA<StateError>())).expect(() => function(), throwsA(isA<ArgumentError>())) (synchronous function throwing is fine with expect).expectLaterUse await expectLater(...) when testing async behavior to ensure proper sequencing.
// GOOD: Waits for future to complete before checking side effects
await expectLater(future, completion(equals(42)));
expect(sideEffectState, equals('done'));
// BAD: Side effect check might run before future completes
expect(future, completion(equals(42)));
expect(sideEffectState, equals('done')); // Race condition!
if statements or for loops for assertions; let matchers handle it.containsPair for maps instead of checking keys manually).dart-test-fundamentals : Core concepts for structuring tests, lifecycles, and configuration.dart-checks-migration : Use this skill if you are migrating tests from package:matcher to modern package:checks.Weekly Installs
61
Repository
GitHub Stars
120
First Seen
Feb 16, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
antigravity45
github-copilot27
codex26
opencode25
gemini-cli25
cursor25
测试策略完整指南:单元/集成/E2E测试金字塔与自动化实践
11,200 周安装
SQLMap数据库渗透测试指南:自动化SQL注入检测与利用方法
72 周安装
Superhuman UI 设计规范:AI 驱动的界面构建指南与设计系统
72 周安装
iOS MapKit API 参考指南:SwiftUI Map (iOS 17+) 与 MKMapView 完整对比与使用教程
78 周安装
iOS设计系统最佳实践:SwiftUI 6.2 Airbnb风格指南,含50条架构与治理规则
74 周安装
Tauri桌面应用开发与安全指南:IPC安全、能力系统、CSP配置最佳实践
45 周安装
市场与技术调研框架:公司概况、痛点分析、技术栈评估与决策指南
72 周安装
const