generated from JoshuaKGoldberg/create-typescript-app
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add a few more unit tests (#262)
## PR Checklist - [x] Addresses an existing open issue: continues on #7, #8 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/ts-api-utils/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/ts-api-utils/blob/main/.github/CONTRIBUTING.md) were taken ## Overview It's been bugging me that this package now has >2.5 million downloads but only has 46% coverage. Which Codecov shows as a red color in the badge. 😡 No end user impacts here. Just added test coverage.
- Loading branch information
1 parent
9157e31
commit 116f976
Showing
6 changed files
with
258 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import ts from "typescript"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { createSourceFileAndTypeChecker } from "../../test/utils"; | ||
import { | ||
isBigIntLiteralType, | ||
isFalseLiteralType, | ||
isLiteralType, | ||
isNumberLiteralType, | ||
isStringLiteralType, | ||
isTemplateLiteralType, | ||
isTrueLiteralType, | ||
} from "./literal"; | ||
|
||
describe.each([ | ||
["isBigIntLiteralType", isBigIntLiteralType, "0", "0n"], | ||
["isLiteralType", isLiteralType, "number", "0"], | ||
["isNumberLiteralType", isNumberLiteralType, "number", "0"], | ||
["isStringLiteralType", isStringLiteralType, "string", "''"], | ||
["isTemplateLiteralType", isTemplateLiteralType, "''", "`abc${string}`"], | ||
["isTrueLiteralType", isTrueLiteralType, "boolean", "true"], | ||
["isFalseLiteralType", isFalseLiteralType, "boolean", "false"], | ||
])(`%s`, (name, typeGuard, falseCase, trueCase) => { | ||
describe(name, () => { | ||
it.each([ | ||
[false, falseCase], | ||
[true, trueCase], | ||
])('returns %j when given "%s"', (expected, source) => { | ||
const { sourceFile, typeChecker } = createSourceFileAndTypeChecker(` | ||
declare const x: ${source}; | ||
`); | ||
|
||
const node = (sourceFile.statements[0] as ts.VariableStatement) | ||
.declarationList.declarations[0].name; | ||
|
||
const type = typeChecker.getTypeAtLocation(node); | ||
|
||
expect(typeGuard(type)).toEqual(expected); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters