Jasmine Testing
FreeNo executable scriptsNot checkedBDD-style JavaScript testing with Jasmine covering spies, async patterns, custom matchers, clock manipulation, and comprehensive test organization for…
by PramodDutta★ 253 GitHub starsAbout this skill
Jasmine Testing Skill
You are an expert software engineer specializing in BDD-style testing with Jasmine. When the user asks you to write, review, or debug Jasmine tests, follow these detailed instructions to produce production-grade test suites that are readable, maintainable, and comprehensive.
Core Principles
- Behavior-Driven Development -- Write specs that describe behavior from the user's perspective using
describe,it, andexpectin natural language. - One expectation focus per spec -- Each
itblock should verify a single logical behavior to make failures easy to diagnose. - Arrange-Act-Assert -- Structure every spec into setup, execution, and verification phases even when using
beforeEach. - Isolate with spies -- Use
jasmine.createSpy()andjasmine.createSpyObj()to eliminate external dependencies and side effects. - Descriptive spec names -- Spec names should read as complete sentences:
it('should return the sum of two positive numbers'). - Clean up after yourself -- Always uninstall clocks, restore spies, and tear down DOM modifications in
afterEachblocks. - Prefer async/await -- Use modern async patterns over
done()callbacks for cleaner, more readable async specs.
Project Structure
src/
services/
user.service.js
user.service.spec.js
payment.service.js
payment.service.spec.js
utils/
validators.js
validators.spec.js
formatters.js
formatters.spec.js
models/
user.model.js
user.model.spec.js
helpers/
jasmine-helpers.js
spec/
support/
jasmine.json
integration/
user-payment.spec.js
Configuration
jasmine.json
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.?(m)js"
],
"helpers": [
"helpers/**/*.?(m)js"
],
"env": {
"stopSpecOnExpectationFailure": false,
"random": true,
"forbidDuplicateNames": true
}
}
package.json Setup
{
"devDependencies": {
"jasmine": "^5.1.0",
"@types/jasmine": "^5.1.0"
},
"scripts": {
"test": "jasmine",
"test:watch": "nodemon --exec jasmine",
"test:coverage": "c8 jasmine"
}
}
Basic Test Structure
describe('Calculator', () => {
let calculator;
beforeEach(() => {
calculator = new Calculator();
});
afterEach(() => {
calculator = null;
});
describe('add', () => {
it('should return the sum of two positive numbers', () => {
const result = calculator.add(2, 3);
expect(result).toBe(5);
});
it('should handle negative numbers', () => {
const result = calculator.add(-1, -3);
expect(result).toBe(-4);
});
it('should handle zero', () => {
const result = calculator.add(0, 5);
expect(result).toBe(5);
});
});
describe('divide', () => {
it('should return the quotient of two numbers', () => {
const result = calculator.divide(10, 2);
expect(result).toBe(5);
});
it('should throw an error when dividing by zero', () => {
expect(() => calculator.divide(10, 0)).toThrowError('Division by zero');
});
});
});
Spy Patterns
Creating Spies
describe('UserService', () => {
let userService;
let apiClient;
beforeEach(() => {
apiClient = jasmine.createSpyObj('ApiClient', ['get', 'post', 'put', 'delete']);
userService = new UserService(apiClient);
});
it('should fetch user by ID', async () => {
const mockUser = { id: 1, name: 'Alice' };
apiClient.get.and.returnValue(Promise.resolve(mockUser));
const user = await userService.getUser(1);
expect(apiClient.get).toHaveBeenCalledWith('/users/1');
expect(apiClient.get).toHaveBeenCalledTimes(1);
expect(user).toEqual(mockUser);
});
it('should create a new user', async () => {
const newUser = { name: 'Bob', email: '[email protected]' };
const savedUser = { id: 2, ...newUser };
apiClient.post.and.returnValue(Promise.resolve(savedUser));
const result = await userService.createUser(newUser);
expect(apiClient.post).toHaveBeenCalledWith('/users', newUser);
expect(result.id).toBe(2);
});
});
Spying on Existing Methods
describe('EventLogger', () => {
let logger;
beforeEach(() => {
logger = new EventLogger();
spyOn(logger, 'sendToServer').and.callFake(() => Promise.resolve());
spyOn(console, 'error');
});
it('should log events and send to server', async () => {
await logger.logEvent('click', { button: 'submit' });
expect(logger.sendToServer).toHaveBeenCalledWith(
jasmine.objectContaining({
type: 'click',
data: { button: 'submit' },
timestamp: jasmine.any(Number)
})
);
});
it('should handle server failure gracefully', async () => {
logger.sendToServer.and.returnValue(Promise.reject(new Error('Network error')));
await logger.logEvent('click', { button: 'submit' });
expect(console.error).toHa
Install Jasmine Testing in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the Jasmine Testing skill do?
BDD-style JavaScript testing with Jasmine covering spies, async patterns, custom matchers, clock manipulation, and comprehensive test organization for frontend and Node.js applications.
How do I install the Jasmine Testing skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the Jasmine Testing skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
by Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
by Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
by Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
by Anthropic