मुख्य सामग्री पर जाएँ
Skillpedia
टेस्टिंग48k · #4988

jest-skill

यह क्या करती है

यह टूल Jest library का इस्तेमाल करके आपके JavaScript या TypeScript code के लिए अपने-आप चलने वाले tests बनाने में मदद करता है। यह basic tests बना सकता है, code के कुछ हिस्सों की नकल (mocking) कर सकता है, asynchronous functions को test कर सकता है, और React components को भी test कर सकता है।

कब इस्तेमाल करें

  • ✓जब आपको यह जांचना हो कि आपका code उम्मीद के मुताबिक काम कर रहा है।
  • ✓यह सुनिश्चित करने के लिए कि नए बदलाव पुरानी कार्यक्षमता को न तोड़ें।
  • ✓जब बाहरी dependencies या जटिल functions की नकल करके test बनाने हों।

Skill का लिंक

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/jest-skill/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/jest-skill/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“'add' function के लिए एक test बनाओ, जो दो numbers लेता है और उनका जोड़ लौटाता है।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

टूल tests लिखने के लिए Jest library का इस्तेमाल करता है। यह tests को व्यवस्थित करने के लिए 'describe' और 'it' नाम के code blocks बनाता है, और 'expect' से जांचता है कि नतीजे उम्मीद के मुताबिक हैं या नहीं।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

Jest Testing Skill

When to Use

Use this skill when you need generates Jest unit and integration tests in JavaScript or TypeScript. Covers mocking, snapshots, async testing, and React component testing. Use when user mentions "Jest", "describe/it/expect", "jest.mock", "toMatchSnapshot". Triggers on: "Jest", "expect().toBe()", "jest.mock",...

Core Patterns

Basic Test

describe('Calculator', () => {
  let calc;
  beforeEach(() => { calc = new Calculator(); });

  test('adds two numbers', () => {
    expect(calc.add(2, 3)).toBe(5);
  });

  test('throws on division by zero', () => {
    expect(() => calc.divide(10, 0)).toThrow('Division by zero');
  });
});

Matchers

expect(value).toBe(exact);                 // === strict
expect(value).toEqual(object);             // deep equality
expect(value).toBeTruthy();
expect(value).toBeNull();
expect(value).toBeGreaterThan(3);
expect(value).toBeCloseTo(0.3, 5);
expect(str).toMatch(/regex/);
expect(arr).toContain(item);
expect(arr).toHaveLength(3);
expect(obj).toHaveProperty('name');
expect(obj).toMatchObject({ name: 'Alice' });
expect(() => fn()).toThrow(CustomError);

Mocking

// Mock function
const mockFn = jest.fn();
mockFn.mockReturnValue(42);
mockFn.mockResolvedValue({ data: 'test' });
expect(mockFn).toHaveBeenCalledWith('arg1');
expect(mockFn).toHaveBeenCalledTimes(1);

// Mock module
jest.mock('./database');
const db = require('./database');
db.getUser.mockResolvedValue({ name: 'Alice' });

// Mock with implementation
jest.mock('./api', () => ({
  fetchUsers: jest.fn().mockResolvedValue([{ name: 'Alice' }]),
}));

// Spy
const spy = jest.spyOn(console, 'log').mockImplementation();
expect(spy).toHaveBeenCalledWith('expected');
spy.mockRestore();

// Fake timers
jest.useFakeTimers();
jest.advanceTimersByTime(1000);
jest.useRealTimers();

Async Testing

test('fetches users', async () => {
  const users = await fetchUsers();
  expect(users).toHaveLength(3);
});

test('resolves with data', () => {
  return expect(fetchData()).resolves.toEqual({ data: 'value' });
});

test('rejects with error', () => {
  return expect(fetchBadData()).rejects.toThrow('not found');
});

React Component Testing (Testing Library)

import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import LoginForm from './LoginForm';

test('submits login form', async () => {
  const onSubmit = jest.fn();
  render(<LoginForm onSubmit={onSubmit} />);

  fireEvent.change(screen.getByLabelText('Email'), {
    target: { value: 'user@test.com' },
  });
  fireEvent.change(screen.getByLabelText('Password'), {
    target: { value: 'password123' },
  });
  fireEvent.click(screen.getByRole('button', { name: /login/i }));

  await waitFor(() => {
    expect(onSubmit).toHaveBeenCalledWith({
      email: 'user@test.com', password: 'password123',
    });
  });
});

Snapshot Testing

test('renders correctly', () => {
  const tree = renderer.create(<Button label="Click" />).toJSON();
  expect(tree).toMatchSnapshot();
});
// Update: jest --updateSnapshot

Anti-Patterns

Bad Good Why
expect(x === y).toBe(true) expect(x).toBe(y) Better errors
No await on async Always await Swallows failures
Snapshot everything Snapshot UI, assert logic Snapshot fatigue

Quick Reference

Task Command
Run all npx jest
Watch npx jest --watch
Coverage npx jest --coverage
Update snapshots npx jest --updateSnapshot
Run file npx jest tests/calc.test.js
Single test test.only('name', () => {})

Deep Patterns

For production-grade patterns, see reference/playbook.md:

Section What's Inside
§1 Production Config Node + React configs, path aliases, coverage thresholds
§2 Mocking Deep Dive Module/partial/manual mocks, spies, timers, env vars
§3 Async Patterns Promises, rejections, event emitters, streams
§4 test.each Array, tagged template, describe.each for table-driven tests
§5 Custom Matchers toBeWithinRange, toBeValidEmail, TypeScript declarations
§6 React Testing Library userEvent, hooks, context providers
§7 Snapshot Testing Component, inline, property matchers
§8 API Service Testing Mocked axios, CRUD patterns, error handling

…

अक्सर पूछे जाने वाले सवाल

'mocking' क्या है?

Mocking का मतलब है आपके code के किसी हिस्से (जैसे function या module) का 'substitute' बनाना, ताकि आप दूसरे हिस्से को अलग से test कर सकें, बिना असली हिस्से पर निर्भर हुए।

'snapshots' क्या हैं?

Snapshots आपके code के expected output की 'फोटो' जैसे होते हैं। अगर output अचानक बदलता है, तो test फेल हो जाता है, जिससे bugs पकड़ने में मदद मिलती है।

मैं 'setTimeout' या 'fetch' इस्तेमाल करने वाले code को कैसे test करूं?

Jest में asynchronous code संभालने के लिए खास tools हैं, जैसे 'async/await' और 'jest.useFakeTimers()', जिनसे ऐसे कामों को भरोसेमंद तरीके से test किया जा सकता है।

जानकारी

लेखक का मूल विवरण

Generates Jest unit and integration tests in JavaScript or TypeScript. Covers mocking, snapshots, async testing, and React component testing. Use when user mentions \"Jest\", \"describe/it/expect\", \"jest.mock\", \"toMatchSnapshot\".

repo: sickn33/agentic-awesome-skills

लोकप्रियता

GitHub स्टार
48k
रैंकिंग में स्थान
#4988
लाइसेंस
MIT
अपडेट की गई
15/10/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

00-andruia-consultant

48k

आपके एजेंट को AI प्रोजेक्ट शुरू करने या उन्हें बेहतर बनाने में मदद करता है। यह code का विश्लेषण करता है, tools सुझाता है और स्पेनिश भाषा में action plan बनाता है।

AI और एजेंटएजेंट

007

48k

आपका एजेंट security audit और threat modeling करता है। यह प्रोजेक्ट को हमलों और कमजोरियों से बचाने में काम आता है।

कोडिंगसिक्योरिटी

10-andruia-skill-smith

48k

आपके एजेंट को AI tools बनाने या उन्हें बेहतर करने में मदद करता है। यह तय करता है कि tools कैसे काम करेंगे, documentation लिखता है और structure की जांच करता है।

AI और एजेंटएजेंट

20-andruia-niche-intelligence

48k

आपका एजेंट किसी खास industry का summary बनाता है। भरोसेमंद स्रोतों की मदद से यह प्रोजेक्ट का संदर्भ, नियम, इस्तेमाल के तरीके और जोखिम समझने में मदद करता है।

लेखन और डॉक्यूमेंटरिसर्च

मिलती-जुलती skills