jestsmith
v1.4.0
Published
An AI powered package that takes in code and an optional description and generates jest testcases for that code"
Maintainers
Readme
🧪 JestSmith
🧠💥 Auto-generate Jest test cases for your JavaScript/TypeScript code using AI — so you can ship confidently without writing a single test.
🚀 What is JestSmith?
JestSmith is a CLI tool that uses AI to automatically generate Jest test cases for any JavaScript or TypeScript project, including:
- ✅ React components
- ✅ Node.js backend logic
- ✅ NestJS modules (controllers, services, routes)
- ✅ Any framework or custom business logic
✨ Features
- ⚡ One-command test generation
- 📂 Folder support (generate tests for entire modules)
- 🧠 AI-powered (works better with a short explanation)
- 📝 Outputs clean, readable, idiomatic Jest tests
- 🧰 Framework-agnostic (React, Node, Angular, NestJS, etc.)
- 🛠️ TypeScript-native
📦 Installation
npm install -g jestsmith🧑💻 Usage
1. Add your OpenAI API_KEY
export OPENAI_API_KEY=<Your OpenAI API KEY>Or
Add this to your project's local .env file:
OPENAI_API_KEY=<Your OpenAI API KEY>2. Generate test for a single file
jestsmith ./src/components/LoginForm.tsx --describe "A login form with Formik + Yup that hits a login API on submit"3. Generate test for a whole folder (e.g., a NestJS module)
jestsmith ./src/modules/user --describe "This is a NestJS User module with CRUD operations"✅ The tool will:
- Parse each file
- Understand file relationships (controllers, services, routes)
- Generate relevant Jest test cases into a
__tests__/folder or in the--out-dir
🛠 CLI Options
| Option | Description |
| ------------ | --------------------------------------------------------- |
| --describe | (optional) Add context so the AI writes better tests |
| --outDir | (optional) Customize the output folder for test files |
| --dry-run | (coming soon) Preview the generated output without saving |
📁 Example
Given a file like:
// LoginForm.tsx
const LoginForm = () => {
const formik = useFormik({
/* yup validation */
});
const handleSubmit = async () => {
await api.login(formik.values);
};
return <form onSubmit={handleSubmit}>...</form>;
};Running:
jestsmith LoginForm.tsx --describe "React login form using Formik and Yup"Might generate:
// __tests__/LoginForm.test.tsx
import { render, fireEvent } from '@testing-library/react';
import LoginForm from '../LoginForm';
describe('LoginForm', () => {
it('calls login API on successful form submission', async () => {
...
});
});📚 How It Works
Under the hood, JestSmith:
- Uses AST parsing to understand your code structure
- Sends intelligently prepared prompts to an LLM (like GPT)
- Applies Jest syntax best practices
- Writes test files based on your code and explanation
💡 Tips for Best Results
- ✅ Provide a short
--describefor context - ✅ Keep functions/components modular and clean
- ✅ Use TypeScript where possible for better inference
- ✅ Use meaningful function/component names
🤖 Roadmap
- [ ]
--dry-runto preview generated code - [ ] Support
.jestsmithrcconfig files - [ ] Built-in Prettier formatting
- [ ] Estimate test coverage based on function count
- [ ] VSCode extension support
🧑🎤 Contributing
PRs, ideas, and contributions are welcome!
🔧 Local Dev
# clone the repo
git clone https://github.com/ahsansheikh94/jestsmith.git
cd jestsmith
# install deps
npm install
# build the CLI
npm run build
# test locally
node dist/bin/index.js ./src/example.ts --describe "Login form with API call"📦 Publishing
This repo uses Changesets for automated versioning + changelogs + npm publishing.
To release:
npx changeset # describe the change
git commit -am "chore: version bump"
git pushGitHub Actions will:
- Create a release PR
- Tag version
- Publish to npm automatically
You’ll need to set
NPM_TOKENin GitHub Secrets.
🪪 License
MIT © Ahsan Sheikh
🌍 Community
Found a bug? Have feature ideas?
→ Open an issue
Love the tool?
→ ⭐ Star it and share it with your team!
