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

javascript-typescript-jest

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

यह टूल Jest library की मदद से आपके JavaScript और TypeScript कोड के लिए tests बनाने में मदद करता है। यह tests को व्यवस्थित करने, बाहरी dependencies (जैसे external APIs) की नकली जगह बनाने (simulate करने), और यह जांचने के सर्वोत्तम तरीके सिखाता है कि सब कुछ अपेक्षा के अनुसार काम कर रहा है।

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

  • ✓जब आप JavaScript या TypeScript में कोड लिखते हों।
  • ✓कोई बदलाव करने के बाद यह पक्का करने के लिए कि कोड सही चल रहा है।
  • ✓बाहरी dependencies की नकल (simulate) करने और सिर्फ़ अपने logic की जांच करने के लिए।

Skill का लिंक

https://github.com/github/awesome-copilot/blob/main/skills/javascript-typescript-jest/SKILL.md

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

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

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

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

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

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

“मैं ऐसे function का टेस्ट कैसे लिखूं जो किसी external API को call करता है?”

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

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

यह टूल आपके tests को अलग-अलग files में व्यवस्थित करता है और tests की संरचना बनाने के लिए `describe` और `it` जैसे commands इस्तेमाल करता है। Dependencies की नकल बनाने के लिए यह `jest.mock` और `jest.spyOn` जैसे functions का उपयोग करता है, जिससे आप अपने कोड को अलग से (isolation में) टेस्ट कर सकते हैं।

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

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

Test Structure

  • Name test files with .test.ts or .test.js suffix
  • Place test files next to the code they test or in a dedicated __tests__ directory
  • Use descriptive test names that explain the expected behavior
  • Use nested describe blocks to organize related tests
  • Follow the pattern: describe('Component/Function/Class', () => { it('should do something', () => {}) })

Effective Mocking

  • Mock external dependencies (APIs, databases, etc.) to isolate your tests
  • Use jest.mock() for module-level mocks
  • Use jest.spyOn() for specific function mocks
  • Use mockImplementation() or mockReturnValue() to define mock behavior
  • Reset mocks between tests with jest.resetAllMocks() in afterEach

Testing Async Code

  • Always return promises or use async/await syntax in tests
  • Use resolves/rejects matchers for promises
  • Set appropriate timeouts for slow tests with jest.setTimeout()

Snapshot Testing

  • Use snapshot tests for UI components or complex objects that change infrequently
  • Keep snapshots small and focused
  • Review snapshot changes carefully before committing

Testing React Components

  • Use React Testing Library over Enzyme for testing components
  • Test user behavior and component accessibility
  • Query elements by accessibility roles, labels, or text content
  • Use userEvent over fireEvent for more realistic user interactions

Common Jest Matchers

  • Basic: expect(value).toBe(expected), expect(value).toEqual(expected)
  • Truthiness: expect(value).toBeTruthy(), expect(value).toBeFalsy()
  • Numbers: expect(value).toBeGreaterThan(3), expect(value).toBeLessThanOrEqual(3)
  • Strings: expect(value).toMatch(/pattern/), expect(value).toContain('substring')
  • Arrays: expect(array).toContain(item), expect(array).toHaveLength(3)
  • Objects: expect(object).toHaveProperty('key', value)
  • Exceptions: expect(fn).toThrow(), expect(fn).toThrow(Error)
  • Mock functions: expect(mockFn).toHaveBeenCalled(), expect(mockFn).toHaveBeenCalledWith(arg1, arg2)
अक्सर पूछे जाने वाले सवाल

'Mocks' क्या होते हैं?

Mocks आपके कोड के हिस्सों (जैसे functions या modules) के नकली रूप होते हैं, जिन्हें टेस्टिंग के दौरान इस्तेमाल किया जाता है। इनसे आप इन हिस्सों के व्यवहार को नियंत्रित कर सकते हैं और अपने कोड को बाहरी या जटिल सिस्टम पर निर्भर हुए बिना टेस्ट कर सकते हैं।

Tests क्यों लिखें?

Tests यह पक्का करने में मदद करते हैं कि आपका कोड अपेक्षा के अनुसार काम कर रहा है, और बदलाव करते समय गलतियां जल्दी पकड़ में आती हैं। इससे आपको भरोसा रहता है कि कोड आसानी से टूटेगा नहीं।

'Snapshot testing' क्या है?

Snapshot testing user interface या जटिल data structures को टेस्ट करने की एक तकनीक है। यह अपेक्षित आउटपुट का 'snapshot' लेता है और बाद के tests में मौजूदा आउटपुट को उस snapshot से मिलाकर देखता है कि कोई अनपेक्षित बदलाव तो नहीं हुआ।

जानकारी

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

Best practices for writing JavaScript/TypeScript tests using Jest, including mocking strategies, test structure, and common patterns.

repo: github/awesome-copilot

लोकप्रियता

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

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

0

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

कमेंट

  • …

इस repository की और skills

acquire-codebase-knowledge

40k

आपके एजेंट को किसी मौजूदा code प्रोजेक्ट को समझने और उसका documentation बनाने में मदद करता है। यह नए लोगों को प्रोजेक्ट से जोड़ने या architecture का सार जानने में उपयोगी है।

लेखन और डॉक्यूमेंटडॉक्यूमेंटेशन

acreadiness-assess

40k

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

लेखन और डॉक्यूमेंटडॉक्यूमेंटेशन

acreadiness-generate-instructions

40k

आपके एजेंट को assessment के आधार पर AI tools के लिए निर्देश बनाने में मदद करता है। यह बताता है कि AI कोड के साथ बेहतर कैसे काम करे और पहचानी गई कमियाँ कैसे दूर हों।

लेखन और डॉक्यूमेंटडॉक्यूमेंटेशन

acreadiness-policy

40k

आपके एजेंट को AI प्रोजेक्ट assessment के लिए नीतियाँ तय करने या लागू करने में मदद करता है। यह प्रोजेक्ट्स के मूल्यांकन को मानक बनाने और compliance सुनिश्चित करने में उपयोगी है।

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

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