Assertion libraries
Skill Amey-Thakur/AI-SKILLS/skills/testing/assertion-libraries
Plug-and-play skills and prompts for every AI coding agent
npx -y skills add Amey-Thakur/AI-SKILLS --skill assertion-librariesAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- 20 days oldThe repository was created 20 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
- 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Pick an assertion style and write checks that fail with a message you can diagnose without a debugger. Use when test failures read as "expected true, got false" and you cannot tell what actually broke.
SKILL.md
3.1 KB, 660 tokens by cl100k_base, as published. Nobody here has run it
Assertion libraries
An assertion is where a test states what it expects, and its output is the
first thing you read when it fails. A bare assert result prints "false" and
tells you nothing; a good assertion prints the expected value, the actual
value, and enough of the surrounding structure to locate the divergence. The
library and style you choose largely decide which of those two failures you get.
Method
- Prefer expressive matchers over boolean asserts. Reach for an assertion
that captures both sides:
assertThat(actual).isEqualTo(expected),expect(x).toEqual(y),result.should.equal(...). On failure these print a structured diff; a hand-rolledassert a == bprints only the line, not the values. - Assert the specific property, not a coarse truth.
expect(list).toContain(x)andassertThat(user.name).isEqualTo("Ada")fail with a precise message.assert x in listreduced to a boolean throws away the values, so wrap the value, not the comparison result. - Use deep and structural matchers for objects and collections. Compare
whole structures with
toEqualorisEqualTodeep equality and pick out fields with matchers (objectContaining,hasItem, AssertJ extracting) so the failure shows which field of which element differs, not just "objects not equal". - Keep one logical assertion per test, or group them. A test that checks
six unrelated things stops at the first failure and hides the rest. Split
them, or use a soft-assertion block (
SoftAssertions,expect.soft) that reports every failure in one run when the checks genuinely belong together. - Write custom matchers for domain concepts. When you repeatedly assert the
same shape, define a matcher (
toBeValidOrder, a HamcrestTypeSafeMatcher) so the test reads in domain terms and the failure message speaks that language instead of dumping raw fields every time. - Assert on errors by type and message, not just that something threw. Use
assertRaises(ValueError, match="negative amount")orexpect(fn).toThrow(/negative/)so a test cannot pass on the wrong exception. Catching bareExceptionhides the case where the code failed for an unrelated reason.
Litmus tests
- From a failure message alone, without opening the test, can you tell what value was wrong?
- Does an equality failure on an object show a field-level diff, not "not equal"?
- Does an error assertion pin the exception type and message, so a different failure would not pass it?
Boundaries
This is about assertion style and readable failures, not what to assert, which is a design question the test's purpose answers. Snapshot assertions are a distinct trade-off with their own failure mode. Stay with the assertion library a project has adopted rather than mixing three dialects in one suite.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.