Developer tools dump stack traces, exit codes, and jargon. Figuring out *what to do next* often means searching the same Stack Overflow answers again.
| 1 | """TypeScript rule tests.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import pytest |
| 6 | |
| 7 | from why_failed.matcher import analyze |
| 8 | |
| 9 | CASES = [ |
| 10 | ("error TS2307: Cannot find module 'lodash'", "typescript.ts2307"), |
| 11 | ("error TS2322: Type 'string' is not assignable to type 'number'.", "typescript.ts2322"), |
| 12 | ("error TS2339: Property 'foo' does not exist on type 'Bar'.", "typescript.ts2339"), |
| 13 | ("error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.", "typescript.ts2345"), |
| 14 | ("error TS7006: Parameter 'x' implicitly has an 'any' type.", "typescript.ts7006"), |
| 15 | ("error TS2551: Property 'nmae' does not exist on type 'User'. Did you mean 'name'?", "typescript.ts2551"), |
| 16 | ] |
| 17 | |
| 18 | |
| 19 | @pytest.mark.parametrize("text,rule_id", CASES) |
| 20 | def test_typescript_rules(text: str, rule_id: str) -> None: |
| 21 | result = analyze(text) |
| 22 | assert result.match is not None |
| 23 | assert result.match.rule_id == rule_id |