Token导航 LogoToken导航TokenDH.com
开发规范只读github未标认证来源可访问许可证需确认审计通过

dart-matcher-best-practicesDart 匹配器最佳实践

Agent Skill

dart-matcher-best-practices 用于记录任务执行中的错误、用户纠正、经验和能力缺口,适合在 Codex、Claude、Cursor、Gemini CLI 中希望让 Agent 持续沉淀问题、修正和最佳实践时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

2,646

周安装

106

GitHub Stars

131

下载量

856
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:dart-matcher-best-practices(Dart 匹配器最佳实践)
来源仓库:https://github.com/kevmoo/dash_skills
仓库路径:skills/dart-matcher-best-practices
安装命令:
npx skills add https://github.com/kevmoo/dash_skills --skill dart-matcher-best-practices
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/kevmoo/dash_skills --skill dart-matcher-best-practices

简介

dart-matcher-best-practices 指导如何使用 expect 和 package:matcher 编写清晰高效的测试断言。

  • 适用于迁移旧式手动检查、调试模糊测试失败或提升单元测试可读性的场景。
  • 推荐用 hasLength 替代 .length 比较,用 isEmpty/true 专用 matcher 简化布尔判断。
  • 使用前请确认测试文件已导入 package:matcher 或 package:checks(迁移后)。
  • 涉及复杂匹配时建议添加自定义描述,便于失败时快速定位问题根源。

SKILL.md

Dart Matcher Best Practices

When to use this skill

Use this skill when:

  • Writing assertions using expect and package:matcher.
  • Migrating legacy manual checks to cleaner matchers.
  • Debugging confusing test failures.

Discovery

To find candidates for improving matcher usage, search for suboptimal patterns:

Suboptimal Length Checks

Search for length checks that should use hasLength:

  • Regex: expect\([^,]+.length,\s*

Suboptimal Boolean Checks

Search for checks on boolean properties that have specific matchers:

  • Regex: expect\([^,]+.isEmpty,\s*(true|equals\(true\))
  • Regex: expect\([^,]+.isNotEmpty,\s*(true|equals\(true\))
  • Regex: expect\([^,]+.contains\(.*\),\s*(true|equals\(true\))

Suboptimal Map Lookups

Search for manual map lookups instead of containsPair:

  • Regex: expect\([^,]+\[.*\],\s*

Core Matchers

1. Collections (hasLength, contains, isEmpty, unorderedEquals, containsPair)

  • hasLength(n):

- Prefer expect(list, hasLength(n)) over expect(list.length, n). - Gives better error messages on failure (shows actual list content).

  • isEmpty / isNotEmpty:

- Prefer expect(list, isEmpty) over expect(list.isEmpty, true). - Prefer expect(list, isNotEmpty) over expect(list.isNotEmpty, true).

  • contains(item):

- Verify existence without manual iteration. - Prefer over expect(list.contains(item), true).

  • unorderedEquals(items):

- Verify contents regardless of order. - Prefer over expect(list, containsAll(items)).

  • containsPair(key, value):

- Verify a map contains a specific key-value pair. - Prefer over checking expect(map[key], value) or expect(map.containsKey(key), true).

2. Type Checks (isA<T> and TypeMatcher<T>)

  • isA<T>():

- Prefer for inline assertions: expect(obj, isA<Type>()). - More concise and readable than TypeMatcher<Type>(). - Allows chaining constraints using .having().

  • TypeMatcher<T>:

- Prefer when defining top-level reusable matchers. - Use const: const isMyType = TypeMatcher<MyType>(); - Chaining .having() works here too, but the resulting matcher is not const.

3. Object Properties (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.

4. Async Assertions

  • completion(matcher):

- Wait for a future to complete and check its value. - Prefer await expectLater(...) to ensure the future completes before the test continues. - await expectLater(future, completion(equals(42))).

  • throwsA(matcher):

- Check that a future or function throws an exception. - await expectLater(future, throwsA(isA<StateError>())). - expect(() => function(), throwsA(isA<ArgumentError>())) (synchronous function throwing is fine with expect).

5. Using expectLater

Use 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!

Principles

  1. Readable Failures: Choose matchers that produce clear error messages.
  2. Avoid Manual Logic: Don't use if statements or for loops for assertions; let matchers handle it.
  3. Specific Matchers: Use the most specific matcher available (e.g., containsPair for maps instead of checking keys manually).

Related Skills

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.67%
按下载量换算288

Claude

28%
按下载量换算240

Cursor

20.68%
按下载量换算177

Gemini CLI

8.82%
按下载量换算75

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills