mock-best-practices
यह क्या करती है
यह स्किल देखती है कि टेस्ट फ़ाइल mocks का इस्तेमाल कैसे करती है, यानी कोड के बाहरी हिस्सों की जगह लेने वाले स्टैंड-इन। यह उन डेवलपर्स के लिए है जो ऐसे टेस्ट चाहते हैं जो असली समस्याएँ पकड़ें, न कि सिर्फ़ पास हो जाएँ।
कब इस्तेमाल करें
- ✓जब आप एजेंट से टेस्ट फ़ाइल में mocks के इस्तेमाल की समीक्षा चाहते हैं।
- ✓जब टेस्ट पास होते हैं पर असली ऐप टूटती है, और आपको शक है कि बहुत ज़्यादा mock हो रहा है।
- ✓जब आप नए टेस्ट लिख रहे हैं और जानना चाहते हैं कि किसे mock करें और किसे असली रखें।
Skill का लिंक
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/mock-best-practices/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मेरे टेस्ट पास होते हैं पर ऐप फिर भी टूटती है। क्या आप जाँच सकते हैं कि मैं बहुत ज़्यादा mock तो नहीं कर रहा?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
एजेंट टेस्ट फ़ाइल पढ़ता है और ऐसे mocks खोजता है जो बिज़नेस लॉजिक छिपाते हैं, जहाँ सफ़ाई नहीं होती, और ऐसे टेस्ट जो आंतरिक विवरण जाँचते हैं। फिर वह ज़रूरी न होने वाले mocks हटाने और सही स्तर पर mock करने का सुझाव देता है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Follow mocking best practices
Proper mocking isolates units under test while keeping tests realistic—over-mocking creates false confidence when tests pass but production breaks.
Quick Reference
- Mock external dependencies (APIs, databases, file system), not business logic
- Always clean up mocks with jest.restoreAllMocks() in afterEach
- Use MSW for realistic API mocking without coupling to implementation
- Test behavior and outputs, not internal implementation details
Check
Review this test file for mocking patterns, checking for over-mocking, missing mock cleanup, and proper mock implementation.
Fix
Improve mocking strategy by removing unnecessary mocks, adding proper cleanup, and mocking at the right level of abstraction.
Explain
Explain mocking best practices including when to mock, what to mock, and common mocking pitfalls.
Code Review
Review tests, CI workflows, and enforcement points related to Follow mocking best practices. Flag exact gaps where the rule is not automatically verified or where failures do not block regressions.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/testing/mock-best-practices
अक्सर पूछे जाने वाले सवाल
किसे mock करना चाहिए?
स्किल कहती है कि APIs, databases और file system जैसी बाहरी निर्भरताओं को mock करें, बिज़नेस लॉजिक को नहीं।
MSW क्या है?
यह यथार्थवादी API mocking का टूल है, जो इस पर निर्भर नहीं करता कि आपका कोड API को कैसे कॉल करता है।
mocks की सफ़ाई क्यों ज़रूरी है?
टेस्ट के बीच छूटे mocks नतीजे बदल सकते हैं और फ़ेल होने के कारण समझना मुश्किल बना सकते हैं।
जानकारी
लेखक का मूल विवरण
Use when reviewing CI coverage, automated checks, or test strategy related to Follow mocking best practices. Focus on whether the rule is continuously verified, not just documented.
लोकप्रियता
- GitHub स्टार
- 75k
- रैंकिंग में स्थान
- #2941
- लाइसेंस
- MIT
- अपडेट की गई
- 31/10/2026
कमेंट
- …
इस repository की और skills
frontendchecklist
75kकमांड-लाइन टूल से फ़्रंटएंड कोड और लाइव पेजों को एक्सेसिबिलिटी, स्पीड, SEO और सिक्योरिटी के 380 से ज़्यादा नियमों से जाँचती है।
frontend-checklist-global
75kफ़्रंटएंड प्रोजेक्ट को Front-End Checklist के सभी 386 नियमों से ऑडिट करती है, और हर मिली समस्या का ठोस समाधान देती है।
404-page
75kजाँचती है कि आपका गुम पेज उपयोगी लिंक देता है और सही 404 स्टेटस लौटाता है, ताकि भटके हुए विज़िटर रास्ता ढूँढ सकें।
about-page
75kजाँचती है कि आपकी साइट पर एक साफ़ About पेज है जो बताता है कि उसे कौन चलाता है, ताकि विज़िटर और सर्च इंजन का भरोसा बढ़े।
मिलती-जुलती skills
test-driven-development
311kयह आपके एजेंट को किसी भी फ़ीचर या सुधार से पहले पहले असफल होने वाला टेस्ट लिखना, उसे असफल होते देखना, फिर पास करने वाला सबसे छोटा कोड लिखना सिखाती है।
verification-before-completion
311kयह आपके एजेंट को किसी काम, सुधार या build के पूरा या पास होने का दावा करने से पहले असली जांच चलाकर उसका आउटपुट पढ़ना सिखाती है।
migrate-to-shoehorn
310kआपकी टेस्ट फ़ाइलों में जोखिम भरे type casts की जगह shoehorn लाइब्रेरी लगाती है, ताकि टेस्ट अधूरे डेटा से भी type checks पास कर सकें।