generated from JoshuaKGoldberg/create-typescript-app
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added an assortment of unit tests (#205)
## PR Checklist - [x] Addresses an existing open issue: starts on #7, #8, #9, #10, #11, #12, #13, #14 - [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 I had some time on a road trip today and was motivated to backfill some tests 😄. Doesn't add in 100% coverage on any file or really finish any of the linked issues. Just raises test coverage across the board in general. Co-authored-by: Rebecca Stevens <rebecca.stevens@outlook.co.nz>
- Loading branch information
1 parent
4ac4813
commit e11775e
Showing
9 changed files
with
822 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import ts from "typescript"; | ||
import { describe, expect, it, vitest } from "vitest"; | ||
|
||
import { forEachComment } from "./comments"; | ||
import { createNodeAndSourceFile } from "./test/utils"; | ||
import { isTsVersionAtLeast } from "./utils"; | ||
|
||
describe("forEachComment", () => { | ||
it("does not call the callback when the source has no comments", () => { | ||
const { node, sourceFile } = createNodeAndSourceFile("let value;"); | ||
const callback = vitest.fn(); | ||
|
||
forEachComment(node, callback, sourceFile); | ||
|
||
expect(callback).not.toHaveBeenCalled(); | ||
}); | ||
|
||
if (isTsVersionAtLeast(4, 3)) { | ||
it("calls the callback when the source has a leading comment", () => { | ||
const { node, sourceFile } = createNodeAndSourceFile(` | ||
// hello world | ||
let value; | ||
`); | ||
const callback = vitest.fn(); | ||
|
||
forEachComment(node, callback, sourceFile); | ||
|
||
expect(callback).toHaveBeenCalledWith( | ||
sourceFile.getFullText(), | ||
expect.objectContaining({ | ||
kind: ts.SyntaxKind.SingleLineCommentTrivia, | ||
}) | ||
); | ||
}); | ||
|
||
it("calls the callback when the source has a trailing comment", () => { | ||
const { node, sourceFile } = createNodeAndSourceFile(` | ||
let value; // hello world | ||
`); | ||
const callback = vitest.fn(); | ||
|
||
forEachComment(node, callback, sourceFile); | ||
|
||
expect(callback).toHaveBeenCalledWith( | ||
sourceFile.getFullText(), | ||
expect.objectContaining({ | ||
kind: ts.SyntaxKind.SingleLineCommentTrivia, | ||
}) | ||
); | ||
}); | ||
} | ||
}); |
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
Oops, something went wrong.