react19-test-patterns
यह क्या करती है
यह गाइड आपके कोड टेस्ट्स को नए React वर्शन (React 19) के साथ काम करने लायक बनाने में मदद करती है। यह दिखाती है कि टेस्ट कोड के वे खास हिस्से कैसे ठीक करें जो काम करना बंद कर गए या बदल गए हैं।
कब इस्तेमाल करें
- ✓जब आप अपने प्रोजेक्ट को React 19 में अपडेट कर रहे हों।
- ✓जब React 18 वाले आपके टेस्ट अपडेट के बाद फ़ेल होने लगें।
- ✓जब आपके टेस्ट में 'act' या 'Simulate' से जुड़े एरर मैसेज दिखें।
Skill का लिंक
https://github.com/github/awesome-copilot/blob/main/skills/react19-test-patterns/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“React 19 के लिए अपने टेस्ट कैसे अपडेट करूं?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
गाइड हर ज़रूरी बदलाव के लिए 'पहले' और 'बाद' के उदाहरण देती है। आपको पुराने कोड की जगह उदाहरणों में दिखाया गया नया कोड लिखना है, ताकि आपके टेस्ट ठीक हो जाएं।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
React 19 Test Migration Patterns
Reference for all test file migrations required by React 19.
Priority Order
Fix test files in this order; each layer depends on the previous:
actimport fix first, it unblocks everything elseSimulate→fireEventfix immediately after act- Full react-dom/test-utils cleanup remove remaining imports
- StrictMode call counts measure actual, don't guess
- Async act wrapping for remaining "not wrapped in act" warnings
- Custom render helper verify once per codebase, not per test
1. act() Import Fix
// Before REMOVED in React 19:
import { act } from 'react-dom/test-utils';
// After:
import { act } from 'react';
If mixed with other test-utils imports:
// Before:
import { act, Simulate, renderIntoDocument } from 'react-dom/test-utils';
// After split the imports:
import { act } from 'react';
import { fireEvent, render } from '@testing-library/react'; // replaces Simulate + renderIntoDocument
2. Simulate → fireEvent
// Before Simulate REMOVED in React 19:
import { Simulate } from 'react-dom/test-utils';
Simulate.click(element);
Simulate.change(input, { target: { value: 'hello' } });
Simulate.submit(form);
Simulate.keyDown(element, { key: 'Enter', keyCode: 13 });
// After:
import { fireEvent } from '@testing-library/react';
fireEvent.click(element);
fireEvent.change(input, { target: { value: 'hello' } });
fireEvent.submit(form);
fireEvent.keyDown(element, { key: 'Enter', keyCode: 13 });
3. react-dom/test-utils Full API Map
| Old (react-dom/test-utils) | New location |
|---|---|
act |
import { act } from 'react' |
Simulate |
fireEvent from @testing-library/react |
renderIntoDocument |
render from @testing-library/react |
findRenderedDOMComponentWithTag |
getByRole, getByTestId from RTL |
findRenderedDOMComponentWithClass |
getByRole or container.querySelector |
scryRenderedDOMComponentsWithTag |
getAllByRole from RTL |
isElement, isCompositeComponent |
Remove not needed with RTL |
isDOMComponent |
Remove |
4. StrictMode Call Count Fixes
React 19 StrictMode no longer double-invokes useEffect in development. Spy assertions counting effect calls must be updated.
Strategy always measure, never guess:
# Run the failing test, read the actual count from the error:
npm test -- --watchAll=false --testPathPattern="[filename]" --forceExit 2>&1 | grep -E "Expected|Received"
// Before (React 18 StrictMode effects ran twice):
expect(mockFn).toHaveBeenCalledTimes(2); // 1 call × 2 (strict double-invoke)
// After (React 19 StrictMode effects run once):
expect(mockFn).toHaveBeenCalledTimes(1);
// Render-phase calls (component body) still double-invoked in React 19 StrictMode:
expect(renderSpy).toHaveBeenCalledTimes(2); // stays at 2 for render body calls
अक्सर पूछे जाने वाले सवाल
'act' क्या है?
'act' एक फ़ंक्शन है जिसे टेस्ट में इस्तेमाल किया जाता है, ताकि नतीजा जांचने से पहले UI के अपडेट हो जाएं। React 19 में 'act' को इम्पोर्ट करने का तरीका बदल गया है।
'Simulate' क्या है?
'Simulate' टेस्ट में यूज़र की क्रियाओं (जैसे क्लिक या टाइपिंग) की नकल करने का तरीका था। React 19 में इसकी जगह 'fireEvent' आ गया है।
React 19 में मेरे टेस्ट में फ़ंक्शन दो बार क्यों बुलाए जा रहे हैं?
React 19 में 'StrictMode' (बग ढूंढने में मदद करने वाला मोड) development में कुछ फ़ंक्शन्स, जैसे `useEffect`, को अब दो बार नहीं चलाता। इसलिए आपको टेस्ट में कॉल की गिनती इस बदलाव के हिसाब से ठीक करनी होगी।
जानकारी
लेखक का मूल विवरण
Provides before/after patterns for migrating test files to React 19 compatibility, including act() imports, Simulate removal, and StrictMode call count changes.
repo: github/awesome-copilot
लोकप्रियता
- GitHub स्टार
- 40k
- रैंकिंग में स्थान
- #7391
- लाइसेंस
- 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 पास कर सकें।