Write tests for the akash-network/console monorepo following established team patterns and reviewer expectations. Use this skill whenever you need to write, fix, review, or refactor tests in the console project — including unit tests, functional tests, integration tests, or E2E tests for both frontend (deploy-web) and backend (api, notifications, indexer, provider-proxy). Also trigger when the user mentions 'write tests', 'add tests', 'fix tests', 'test this', 'spec file', or asks about testing patterns in the console codebase. When in doubt about whether to use this skill for a testing task in this repo, USE IT.
90
86%
Does it follow best practices?
Impact
98%
1.81xAverage score across 3 eval scenarios
Passed
No known issues
This skill encodes the testing conventions and patterns for the akash-network/console monorepo.
Before writing any test, read the source file you're testing thoroughly. Understand what it does, what dependencies it has, and what level of testing is appropriate.
Choose the lowest-effective test level. Writing E2E tests for logic that can be unit tested wastes everyone's time and creates brittle, slow suites.
Unit tests (99% of cases):
Integration tests (service + database):
Functional / API tests (black-box HTTP):
nock (v14+ supports native fetch in addition to http/https)E2E tests (post-deployment verification):
setup Function PatternThis is the most important convention. Never use beforeEach with shared mutable variables.
setup() function at the bottom of the root describe blocksetup() independently — no shared mutable state across testsdescribe(BalancesService.name, () => {
it("returns balances for a given address", async () => {
const { service, balanceRepository } = setup();
balanceRepository.findByAddress.mockResolvedValue([{ denom: "uakt", amount: "1000" }]);
const result = await service.getBalances("akash1abc...");
expect(result).toEqual([{ denom: "uakt", amount: "1000" }]);
});
it("returns empty array when no balances found", async () => {
const { service, balanceRepository } = setup();
balanceRepository.findByAddress.mockResolvedValue([]);
const result = await service.getBalances("akash1xyz...");
expect(result).toEqual([]);
});
function setup(input?: { customConfig?: Partial<BalancesConfig> }) {
const balanceRepository = mock<BalanceRepository>();
const config = mockConfigService<BalancesConfig>({ ...input?.customConfig });
const service = new BalancesService(balanceRepository, config);
return { service, balanceRepository, config };
}
});Skip setup only if creating the object under test is trivially simple (e.g., testing a pure function with no dependencies).
Root describe: Use SubjectUnderTest.name (the actual reference, not a string). This enables IDE refactoring and reference-finding.
// Good
describe(StripeWebhookService.name, () => { ... });
// Bad
describe("StripeWebhookService", () => { ... });Nested describe: Use either a method name or a "when ..." condition.
describe(StripeWebhookService.name, () => {
describe("handleChargeRefunded", () => { ... });
describe("when payment method is missing", () => { ... });
});it blocks: Use present simple, 3rd person singular. Do NOT prepend with "should".
// Good
it("returns early when customer ID is missing", async () => { ... });
it("updates both limits and isTrialing when endTrial is true", async () => { ... });
// Bad
it("should return early when customer ID is missing", async () => { ... });mock<T>() from vitest-mock-extendedAlways use mock<T>() for typed mocks. Never use jest.mock() or vi.mock() for module-level mocking — it causes OOM with heavy component trees and couples tests to implementation details.
import { mock } from "vitest-mock-extended";
const userRepository = mock<UserRepository>();
const stripeService = mock<StripeService>();
const logger = mock<LoggerService>();Prefer mock<T>() over as unknown as <Type> for hand-built doubles. When stubbing a hook return value or service that has many fields, build it with mock<T>() and override only the fields the test cares about. Hand-built objects coerced through as unknown as silently survive contract changes upstream and hide real regressions.
// Good — stays in sync with the real type, lets the test focus on what matters
const useCustomUser: typeof DEPENDENCIES.useCustomUser = () =>
mock<ReturnType<typeof DEPENDENCIES.useCustomUser>>({
user: { username: "alice" },
isLoading: false
});
// Bad — `UseCustomUser` could grow a required field and this still compiles
const useCustomUser = () =>
({ user: { username: "alice" }, isLoading: false }) as unknown as ReturnType<typeof DEPENDENCIES.useCustomUser>;Reserve as unknown as for the rare case where the type is structurally incompatible (e.g. branded types) and mock<T>() cannot satisfy it.
For config services, use mockConfigService<T>() (in apps/api/test/mocks/config-service.mock.ts):
const billingConfig = mockConfigService<BillingConfigService>({
DEPLOYMENT_GRANT_DENOM: "uakt",
TRIAL_ALLOWANCE_EXPIRATION_DAYS: 14
});Always explicitly import from vitest:
import { describe, expect, it, vi } from "vitest";Explicit imports make dependencies visible and simplify TypeScript types.
if Statements in AssertionsNever use conditional logic in test expectations. If you need to narrow a type, use as assertions. Otherwise, skipped assertions silently pass when they shouldn't.
// Good
const result = await service.validate(cert) as CertValidationResultError;
expect(result.ok).toBe(false);
expect(result.code).toBe("unknownCertificate");
// Bad
const result = await service.validate(cert);
if (!result.ok) {
expect(result.code).toBe("unknownCertificate");
}Follow the AAA pattern. Setup prepares state; the test validates it. Don't mix concerns.
it("creates a deployment grant", async () => {
// Arrange
const { service, grantService } = setup();
grantService.create.mockResolvedValue(mockGrant);
// Act
const result = await service.createGrant("akash1abc...");
// Assert
expect(result).toEqual(mockGrant);
expect(grantService.create).toHaveBeenCalledWith("akash1abc...");
});Remove obvious comments. If a comment just restates the method name or assertion, delete it.
When testing error paths, focus on errors the code explicitly handles — but don't skip error coverage just because the happy path works. If a service catches and transforms errors, test those paths. If important error scenarios aren't handled in production code, that may be a gap worth flagging rather than ignoring.
Read @references/frontend-patterns.md for the full set of frontend-specific patterns including the DEPENDENCIES pattern, hook testing, query testing, and container testing.
Key points:
getBy* for presence assertions (toBeInTheDocument()), and queryBy* for absence assertions (not.toBeInTheDocument())DEPENDENCIES export + dependencies prop for component DI (never vi.mock) — this covers components, hooks, and any other heavy importsMockComponents() helper to auto-mock dependenciesuseServices hook, not via DEPENDENCIES propsetupQuery() utility for React Query hook testsrenderHook from @testing-library/react for hook testsRead @references/api-patterns.md for the full set of API-specific patterns including service testing, config mocking, and seeder patterns.
Key points:
mock<T>() dependenciesapps/api/test/seeders/)@faker-js/faker for randomized data in seedersPartial<T> overrides with sensible defaultsRead @references/api-patterns.md for functional test setup details.
Key points:
TestDatabaseService (auto-created, migrated, dropped)nock, not internal servicesfetch()-based helpers) for Hono apps, supertest for NestJS — avoid framework-internal methods like app.request()@nestjs/testing Test.createTestingModule() for DIMockProvider() helper to create NestJS providers with vitest-mock-extended mockssupertest with a real NestJS app and per-file test databasesgetByRole, getByLabel, getByPlaceholder — never CSS selectors or data-testidgetByRole('button', { name: /Submit/ }) — don't add redundant aria-label to buttons that already have textwaitFor(...) instead of setTimeout — timeouts cause flakinessconsole.log or manual screenshots — use Playwright's built-in traces (npx playwright --ui)Promise.all with context.waitForEvent("page") for navigation patternsmy-service.ts → my-service.spec.ts*.spec.tsx for components, *.spec.ts for logicsrc/**/*.spec.tssrc/**/*.integration.tstest/functional/**/*.spec.tstest/e2e/**/*.spec.tstest/seeders/ in each app609b56d
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.