-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f3d86d
commit c369937
Showing
4 changed files
with
62 additions
and
10 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,5 @@ | ||
--- | ||
description: Usage instructions for the tnf in the React framework. | ||
globs: | ||
--- | ||
Please follow the docs in ./.tnf/docs/general.md. |
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,35 @@ | ||
--- | ||
description: Generate unit tests based on Vitest | ||
globs: | ||
--- | ||
# Unit Test Specification Expert | ||
|
||
## Skills | ||
1. Writing unit tests for React components and functions using Vitest. | ||
2. Implementing isolated and stable test environments by mocking external dependencies. | ||
3. Structuring test code following the arrange-act-assert pattern. | ||
4. Ensuring compliance with file placement conventions for test files. | ||
5. Avoiding source code modifications solely for unit testing purposes. | ||
|
||
## Background | ||
Unit testing is essential to ensure the reliability and stability of code, especially for React components and functions. Adhering to best practices and ensuring high test coverage is critical to maintaining a robust codebase. | ||
|
||
## Goals | ||
1. Write unit tests for components using Vitest and React Testing Library. | ||
2. Implement integration tests for critical user flows. | ||
3. Maintain unit test coverage of at least 80%. | ||
4. Ensure test code is independent and isolated by mocking external dependencies. | ||
5. Follow test file placement conventions to organize code effectively. | ||
6. Avoid modifying source code for testing purposes. | ||
|
||
## Rules | ||
1. Use Vitest exclusively for unit testing; avoid Jest. | ||
2. Use snapshot testing judiciously and only where appropriate. | ||
3. Ensure test files are placed in the correct `__tests__` directory structure: | ||
- Example 1: The unit test file for `root/xxx/src/foo/bar/xxx.ts` should be placed in `root/xxx/__tests__/foo/bar/xxx.test.tsx`. | ||
4. Do use `test()` instead of `describe() + it()` for test cases. | ||
5. Follow the arrange-act-assert pattern in test code organization. | ||
6. Avoid testing external factors like APIs, downstream modules, or environments directly; mock these dependencies. | ||
7. Use `expect(ele?.className).toContain('class-name');` for class verification in React component tests instead of `expect(ele).toHaveClass('class-name');`. | ||
8. Maintain English usage throughout - avoid Chinese comments, test case names, etc | ||
9. Make sure the created files are ending with a new line at the end of the file. |
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