Repository navigation
test: set up component tests with happy-dom and Testing Library - #227
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
anurag629
left a comment
There was a problem hiding this comment.
Thanks @Bl1ckxy, this is what #206 asked for. The lib/ tests still run in node, the components project picks up CopyButton.test.tsx in happy-dom, and the test fails when I replace the writeText call. The lockfile only adds the new packages. Lint, all 444 tests, the build and the page check pass on top of develop.
It's your first merged PR here, so come say hi on our Discord too: https://discord.gg/mpGdJyjaRQ
Closes #206
What and why
Sets up component testing infrastructure so future component fixes (like the invoice reset in #201 or the hydration error in #193) can ship with tests that fail before the fix.
Previously,
vitest.config.tsran all tests in thenodeenvironment and only picked uplib/**/*.test.ts. There was no DOM library or Testing Library inpackage.json, so component bugs could not be caught by tests.This PR adds
happy-domand@testing-library/reactas dev dependencies, configures Vitest 4test.projectsto split environments, and includes a proof-of-concept test forCopyButton.Changes
happy-dom,@testing-library/react,@testing-library/domas devDependenciestest.environment/test.includewithtest.projectsarray:libproject →nodeenvironment,lib/**/*.test.ts(unchanged behavior)componentsproject →happy-domenvironment,components/**/*.test.tsx+app/**/*.test.tsxresolve.aliasto each project (Vitest 4 projects don't inherit root config)@testing-library/jest-dom/vitestfor DOM matchersnavigator.clipboard.writeTextwith the correct value and the label changes to "Copied"How I tested this
npm run test→ 18 test files, 444 tests, all passing (443 lib + 1 component)nodeenvironmentnavigator.clipboard.writeTextis removed from the componentnpm run lint→ passesnpm run build→ passesAI assistance
Used an AI assistant (Claude) to research Vitest 4
test.projectsenvironment splitting, debug why happy-dom'snavigator.clipboardcan't be overridden withObject.assign, and draft theCopyButtoncomponent test. Every line of code in this PR was written and verified by me —npm run testpasses 444/444,npm run lintandnpm run buildpass.Type of change
Checklist
npm run lint && npm run test && npm run buildpasses locallyNotes for reviewers
resolve.aliasduplication in each project is required because Vitest 4test.projectsoverride rather than inherit the root config. Without it,@/lib/...imports fail in both projects.Object.definePropertyinstead ofObject.assignbecause happy-dom definesnavigator.clipboardas a getter-only property.