unit-tests
Skill1 starsChanged 7 days agoMITView on GitHub
Authors Jest unit tests for TypeScript services using testdouble, neverthrow ResultAsync, and a structured mocks class. Use when writing or refactoring unit tests, adding test coverage, or when the user asks for tests matching project conventions (Arrange/Act/Assert, explicit mocks, negative-only td.verify).
16 other projects use a version of this.
Adopted by
Most recently taken up by
- LeanMeanCleanApps/CleanModelContextProtocoltheir own version, first seen Nov 8, 2026
- microsoft/vscodetheir own version, first seen Nov 2, 2026
- shangyiy/life-kittheir own version, first seen Nov 1, 2026
- GoogleCloudPlatform/cloud-solutionstheir own version, first seen Nov 1, 2026
- bftelman/skillstheir own version, first seen Oct 13, 2026
- karimtrapper/claude-skillstheir own version, first seen Oct 13, 2026
Used with
Projects with it also use auto-perf-optimize, chat-customizations-editor and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
MicrosoftSkillauto-perf-optimize
Run agent-driven VS Code performance or memory investigations. Use when asked to launch Code OSS, automate a VS Code scenario, run the Chat memory smoke runner, capture renderer heap snapshots, take workflow screenshots, compare run summaries, or drive a repeatable scenario before heap-snapshot analysis.
Also in 5 projects that use this
MicrosoftSkillchat-customizations-editor
Use when working on the Chat Customizations editor — the management UI for agents, skills, instructions, hooks, prompts, MCP servers, and plugins.
Also in 5 projects that use this
OpenCortexIDESkilladd-policy
Use when adding, modifying, or reviewing VS Code configuration policies. Covers the full policy lifecycle from registration to export to platform-specific artifacts. Run on ANY change that adds a `policy:` field to a configuration property.
Also in 4 projects that use this
- +9 more from microsoft
Other versions16 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 16
- microsoft/vscode★ 195ksame name
- posit-dev/positron★ 4.3ksame name
- bklit/bklit-ui★ 1.9ksame name
- NeuralInverse/neuralinverse★ 221same name
- genlayerlabs/genlayer-studio★ 180same name
- OpenCortexIDE/cortexide★ 175same name
- GoogleCloudPlatform/cloud-solutions★ 139same name
- cpkt9762/opencode-vscode-ide★ 17same name
- xAmirHamza77/OmniCode★ 12same name
- shangyiy/life-kit★ 10same name
6 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository9 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- 1shot-apiSkill
- 1shot-walletSkill
- agent-walletSkill
- coinoperatedSkill
- ows-branding-layerSkill
- public-relayerSkill
- webauthn-prf-walletSkill
The file
We split this skill into the rules it gives an agent
6 rules. 0 are common, 1 is distinctive, and 5 are very specific to this project.
0
Common
Most of the 15 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Follow this structure so tests stay readable, explicit, and easy to maintain.
- Very specific: line 47
Use real or fake values deliberately: prefer values that match production shape (UUIDs, 0x-prefixed addresses) so type constructors and …
- Very specific: line 51
Create one class named after the system under test, e.g.
- Very specific: line 77
Avoid td.matchers.anything() in baseline stubs unless the API is truly opaque.
- Very specific: line 125
Use td.verify(..., { times: 0 }) when the test’s purpose is to prove something did not run (e.g.
- Very specific: line 127
When verify is required, still prefer specific arguments where feasible.
“Common” is measured: kept by at least 6 in 10 of the 15 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Unit tests (service / business layer)
Follow this structure so tests stay readable, explicit, and easy to maintain. Reference implementations (in the oneshot monorepo):
packages/signer/test/unit/business/SignerService.test.ts— parameterized mocks class, explicit Redis key matching,getInstance().packages/EVMBaseChain/test/unit/business/EscrowWalletService.test.ts— sharedCommonValues, heavy domain setup in Arrange,factoryService().
Install this skill (consumer / global)
npx skills add 1Shot-API/skills/unit-tests -g -a claude-code -yWhen to use this skill
- Writing or refactoring Jest unit tests for TypeScript services in the oneshot monorepo
- Adding coverage that should match project conventions (testdouble, neverthrow
ResultAsync) - The user asks for tests matching Arrange/Act/Assert, explicit mocks, or negative-only
td.verify
When NOT to use this skill
- Frontend/portal component tests that do not use the service mocks class pattern
- Integration or e2e tests outside the Jest + testdouble service layer style
- Relayer (
1shot-okx-relayer) tests that usebun:testinstead of Jest/testdouble
1. File-level constants
At the top of the test file (after imports), declare named constants used across tests:
- Stable IDs and branded types (
UserId,BusinessId, addresses) so every test uses the same fake identity unless a case needs a different value. - Shared primitives reused in mocks (e.g. JWT strings, chain enum) when they are not test-specific.
Use real or fake values deliberately: prefer values that match production shape (UUIDs, 0x-prefixed addresses) so type constructors and validators behave like production.
2. ClassUnderTestMocks class
Create one class named after the system under test, e.g. SignerServiceMocks, EscrowWalletServiceMocks.
- Constructor parameters: Pass anything that should vary the baseline behavior across tests (e.g.
userId,EServicefor the chain service token). Tests that need the same baseline use the same arguments; divergent tests pass different constructor args or override in Arrange (see below).
3. Dependencies
The mocks class owns every dependency the class-under-test needs:
td.object<Interface>()for each injected port (repository, config provider, Redis, etc.).- Public fields so tests and overrides can reference them (
mocks.kmsRepository,mocks.redisClient, …).
Wire the real constructor in a single factory method:
- Name it
getInstance(),factoryService(), or another clear name; one place constructsnew ClassUnderTest(...).
4. Baseline = happy path in the constructor
In the constructor (or an init() called from it), set td.when(...).thenReturn(...) for the default, success-path behavior:
getConfig()→okAsynca real-enough config object.getRedisClient()→okAsyncthe mock Redis client.- Any stubbed remote call that most tests expect to succeed.
Prefer explicit arguments in td.when():
- Pass concrete
CreateSigningKeyParams-like values, exactRedisKeys.*arrays, ortd.matchers.contains([...])with real key strings when the implementation builds a known list. - Avoid
td.matchers.anything()in baseline stubs unless the API is truly opaque; the tighter the match, the earlier wrong calls fail.
Complex or repeated payloads (resolved user context, config blobs) can be built in protected helpers or factory methods on the mocks class.
5. Public members and factories
Expose on the mocks class:
- Data the SUT needs from outside: e.g.
ruc,config, prebuiltSignerConfig. - Factory methods for verbose objects (
makeRucForUserAndChainService, etc.) when multiple tests need the same shape with small variations.
6. Test structure: Arrange / Act / Assert
Each test(...) (or it(...)) uses three sections with comments:
test("descriptive name", async () => {
// Arrange
const mocks = new SomeServiceMocks(/* baseline params */);
// Optional: td.when overrides for this test only
const svc = mocks.getInstance();
// Act
const result = await svc.someMethod(...);
// Assert
expect(result.isErr()).toBe(true);
// ...
});7. Arrange
- Instantiate
ClassUnderTestMockswith the right constructor args. - Apply overrides after construction: extra
td.when(mocks.dep.method(explicitArgs)).thenReturn(...)for this test only (e.g. kill switch returns["on"]). - End Arrange with
const sut = mocks.getInstance()(orfactoryService()).
8. Act
- Only calls on the system under test (and sometimes one obvious preparatory call if the scenario requires it). No assertions in Act.
9. Assert
- Primary:
expect(...)on the method result — forResultAsync/ neverthrow,result.isOk(),result.isErr(),_unsafeUnwrap(),_unsafeUnwrapErr(),toBeInstanceOf, deep equality on unwrapped values. - Avoid
td.verifyfor happy-path call counts unless the team explicitly wants interaction testing for that case.
10. td.verify — negative guarantees only
Use td.verify(..., { times: 0 }) when the test’s purpose is to prove something did not run (e.g. KMS not called after validation failure, or Redis kill switch short-circuits before repository access).
When verify is required, still prefer specific arguments where feasible; use anything() only for parameters that are intentionally opaque or unstable.
Naming consistency
- Mocks class:
{ClassUnderTest}Mocks(e.g.SignerServiceMocks). - Factory:
getInstance()orfactoryService()— pick one per file and stay consistent. - Fix typos in dependency field names (
repositorynotrepsitory) in new tests.
Checklist for a new test file
- Constants block for shared IDs / tokens / addresses
- Single mocks class with all
td.objectdependencies - Constructor establishes happy-path
td.whenwith explicit values where possible getInstance/factoryServicebuilds the real service- Each test has
// Arrange,// Act,// Assert - Assert focuses on
expecton results;td.verifyonly for must-not-happen side effects
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

