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 पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
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.tsor.test.jssuffix - 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()ormockReturnValue()to define mock behavior - Reset mocks between tests with
jest.resetAllMocks()inafterEach
Testing Async Code
- Always return promises or use async/await syntax in tests
- Use
resolves/rejectsmatchers 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
userEventoverfireEventfor 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
कमेंट
- …
इस 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 सुनिश्चित करने में उपयोगी है।
मिलती-जुलती skills
test-driven-development
311kयह आपके एजेंट को किसी भी फ़ीचर या सुधार से पहले पहले असफल होने वाला टेस्ट लिखना, उसे असफल होते देखना, फिर पास करने वाला सबसे छोटा कोड लिखना सिखाती है।
verification-before-completion
311kयह आपके एजेंट को किसी काम, सुधार या build के पूरा या पास होने का दावा करने से पहले असली जांच चलाकर उसका आउटपुट पढ़ना सिखाती है।
migrate-to-shoehorn
310kआपकी टेस्ट फ़ाइलों में जोखिम भरे type casts की जगह shoehorn लाइब्रेरी लगाती है, ताकि टेस्ट अधूरे डेटा से भी type checks पास कर सकें।