Write tests that are both type-safe and narrowly focused on supported behavior. Use small, typed test helpers or fixtures to eliminate repeated casts and noisy “as any”/”as T” in tests, and ensure test cases reflect the product’s validation rules (don’t test unsupported scenarios).
Why: Cleaner, safer tests are easier to read and maintain; helpers reduce boilerplate and prevent hiding type problems with casts. Keeping tests aligned with validation prevents brittle or misleading coverage.
How to apply:
Example helper (from discussion):
function testFindNodeByElementFqn(
nodes: Array<{ id: string; data: { modelFqn?: string | null } }>,
modelFqn: string
) {
return findNodeByElementFqn(nodes as any, modelFqn as any)
}
Use it to remove casts in many tests and keep the test intent clear.
Example simplified rank test (only supported sibling case):
it('parses element view rank rules for siblings', async ({ expect }) => {
const { parse, services } = createTestServices()
const langiumDocument = await parse(`
specification { element block }
model {
block root {
block childA {}
block childB {}
}
}
views {
view index {
include *
{rank=same; root childA childB}
}
}
`)
const doc = services.likec4.ModelParser.parse(langiumDocument)
const ranks = doc.c4Views[0]!.rules.filter(rule => 'rank' in rule)
expect(ranks).toHaveLength(1)
})
Checklist for PRs/tests:
Enter the URL of a public GitHub repository