Drawing from the content and philosophy of [TestingJavaScript.com][1][3][2], as well as established industry best practices, here are clear cursor rules to guide coding agents on how to test JavaScript and React applications effectively.
Test Behavior, Not Implementation
Keep Tests Small and Focused
Use Descriptive Test Names
Organize Tests by Type and Feature
Mock External Dependencies Only When Necessary
Maintain Test Code Quality
Test Components as Users Would Use Them
Prefer Queries Based on Accessible Attributes
Use the Arrange-Act-Assert (AAA) Pattern
Write Unit, Integration, and End-to-End Tests
Use Jest and React Testing Library for Unit and Component Tests
Automate and Run Tests Regularly
Don’t Test Private/Internal Implementation Details
Don’t Overuse Mocks or Test Helpers
Don’t Rely on Unstable Selectors
USE VITEST INSTEAD OF JEST ALWAYS
| Rule | Rationale/Example |
|-----------------------------------------------|-----------------------------------------------------------------------------------|
| Test behavior, not implementation | Focus on what the user sees, not how it’s built[10][7] |
| Use user-centric queries in React tests | getByText
, getByRole
over .className
[9] |
| Keep tests small, focused, and descriptive | Easier to maintain and debug[4][8] |
| Use Arrange-Act-Assert pattern | Improves clarity and structure[7] |
| Automate and run tests regularly | Detects regressions early[4][6] |
| Avoid over-mocking and unstable selectors | Keeps tests robust and meaningful[8][9][10] |
By following these cursor rules, coding agents can ensure their JavaScript and React application tests are robust, maintainable, and focused on delivering real value to users and developers alike.[1][3][2][4][5][6][7][8][9][10]
Sources [1] www.testingjavascript.com https://www.testingjavascript.com [2] Testing JavaScript | Testing JavaScript https://www.testingjavascript.com/ [3] Testing JavaScript | Testing JavaScript https://www.testingjavascript.com [4] How to Test JavaScript Applications: Tools, Techniques, and Best ... https://codedamn.com/news/programming/test-javascript-applications-tools-techniques [5] How to test React Apps - BrowserStack https://www.browserstack.com/guide/how-to-test-react-apps [6] Testing in JavaScript: Best Practices and Tools - DEV Community https://dev.to/mattryanmtl/testing-in-javascript-best-practices-and-tools-4bkb [7] Testing React Components: Best Practices and Tools - LinkedIn https://www.linkedin.com/pulse/testing-react-components-best-practices-tools-alex-lomia [8] Javascript Unit Testing Best Practices to Follow - BrowserStack https://www.browserstack.com/guide/javascript-testing-best-practices [9] goldbergyoni/javascript-testing-best-practices - GitHub https://github.com/goldbergyoni/javascript-testing-best-practices [10] 13 JavaScript Testing Best Practices You Should Know [2025] https://www.lambdatest.com/blog/javascript-testing-best-practices-you-should-know/ [11] Testing JavaScript Applications | <Blog /> - Colin Brooks https://colinrobertbrooks.github.io/blog/testing-javascript-applications/ [12] How to properly test react applications? What are the best ways to ... https://www.reddit.com/r/reactjs/comments/17kfmuf/how_to_properly_test_react_applications_what_are/ [13] Effective Testing in JavaScript | AppSignal Blog https://blog.appsignal.com/2024/05/08/effective-testing-in-javascript.html [14] React Functional Testing Best Practices - Daily.dev https://daily.dev/blog/react-functional-testing-best-practices [15] How to properly learn testing in JavaScript/TypeScript in 2022 - Reddit https://www.reddit.com/r/reactjs/comments/y4qbap/how_to_properly_learn_testing_in/ [16] How to properly unit test a React component? - Stack Overflow https://stackoverflow.com/questions/38815439/how-to-properly-unit-test-a-react-component [17] JavaScript Unit Testing Tutorial | BrowserStack https://www.browserstack.com/guide/unit-testing-in-javascript [18] React Testing for Beginners: Start Here! - YouTube https://www.youtube.com/watch?v=8Xwq35cPwYg [19] Testing Your JavaScript: Best Practices for Robust Applications. https://dev.to/dharamgfx/testing-your-javascript-best-practices-for-robust-applications-428a [20] Testing React Apps - Jest https://jestjs.io/docs/tutorial-react [21] JavaScript testing: 9 best practices to learn - LogRocket Blog https://blog.logrocket.com/javascript-testing-best-practices/ [22] Best practices for writing good unit tests for components? : r/reactjs https://www.reddit.com/r/reactjs/comments/wqy6rz/best_practices_for_writing_good_unit_tests_for/ [23] How to quickly test some javascript code? [closed] - Stack Overflow https://stackoverflow.com/questions/8869783/how-to-quickly-test-some-javascript-code