react18-enzyme-to-rtl
यह क्या करती है
यह टूल आपके code के tests को update करने में मदद करता है। अगर आपने अपने React code की testing के लिए पुराने tool Enzyme का इस्तेमाल किया था, तो यह टूल आपको नए tool React Testing Library पर जाने में मदद करता है, जो React 18 के लिए बेहतर है।
कब इस्तेमाल करें
- ✓पुराने Enzyme tests को React 18 के साथ काम करने लायक बनाने के लिए।
- ✓React project update करने के बाद जब आपके Enzyme tests काम करना बंद कर दें।
- ✓जब आप React code को इस तरह test करना चाहते हैं कि वह user को स्क्रीन पर क्या दिखता है और user क्या करता है, इस पर ध्यान दे, न कि अंदरूनी details पर।
Skill का लिंक
https://github.com/github/awesome-copilot/blob/main/skills/react18-enzyme-to-rtl/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मैं Enzyme का ऐसा test, जो component की अंदरूनी state जाँचता है, React Testing Library इस्तेमाल करने के लिए कैसे बदलूँ?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
टूल पुराने Enzyme functions को नए React Testing Library functions से जोड़ता है। यह दिखाता है कि अपने tests को कैसे फिर से लिखें ताकि वे अंदरूनी details के बजाय स्क्रीन पर दिखने वाले user के व्यवहार पर ध्यान दें।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
React 18 Enzyme → RTL Migration
Enzyme has no React 18 adapter and no React 18 support path. All Enzyme tests must be rewritten using React Testing Library.
The Philosophy Shift (Read This First)
Enzyme tests implementation. RTL tests behavior.
// Enzyme: tests that the component has the right internal state
expect(wrapper.state('count')).toBe(3);
expect(wrapper.instance().handleClick).toBeDefined();
expect(wrapper.find('Button').prop('disabled')).toBe(true);
// RTL: tests what the user actually sees and can do
expect(screen.getByText('Count: 3')).toBeInTheDocument();
expect(screen.getByRole('button', { name: /submit/i })).toBeDisabled();
This is not a 1:1 translation. Enzyme tests that verify internal state or instance methods don't have RTL equivalents - because RTL intentionally doesn't expose internals. Rewrite the test to assert the visible outcome instead.
API Map
For complete before/after code for each Enzyme API, read:
references/enzyme-api-map.md- full mapping: shallow, mount, find, simulate, prop, state, instance, configurereferences/async-patterns.md- waitFor, findBy, act(), Apollo MockedProvider, loading states, error states
Core Rewrite Template
// Every Enzyme test rewrites to this shape:
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import MyComponent from './MyComponent';
describe('MyComponent', () => {
it('does the thing', async () => {
// 1. Render (replaces shallow/mount)
render(<MyComponent prop="value" />);
// 2. Query (replaces wrapper.find())
const button = screen.getByRole('button', { name: /submit/i });
// 3. Interact (replaces simulate())
await userEvent.setup().click(button);
// 4. Assert on visible output (replaces wrapper.state() / wrapper.prop())
expect(screen.getByText('Submitted!')).toBeInTheDocument();
});
});
RTL Query Priority (use in this order)
getByRole- matches accessible roles (button, textbox, heading, checkbox, etc.)getByLabelText- form fields linked to labelsgetByPlaceholderText- input placeholdersgetByText- visible text contentgetByDisplayValue- current value of input/select/textareagetByAltText- image alt textgetByTitle- title attributegetByTestId-data-testidattribute (last resort)
Prefer getByRole over getByTestId. It tests accessibility too.
Wrapping with Providers
// Enzyme with context:
const wrapper = mount(
<ApolloProvider client={client}>
<ThemeProvider theme={theme}>
<MyComponent />
</ThemeProvider>
</ApolloProvider>
);
// RTL equivalent (use your project's customRender or wrap inline):
import { render } from '@testing-library/react';
render(
<MockedProvider mocks={mocks} addTypename={false}>
<ThemeProvider theme={theme}>
<MyComponent />
</ThemeProvider>
</MockedProvider>
);
// Or use the project's customRender helper if it wraps providers
अक्सर पूछे जाने वाले सवाल
मैं अब Enzyme क्यों इस्तेमाल नहीं कर सकता?
Enzyme अब update नहीं होता और नए React versions (जैसे React 18) के साथ काम नहीं करता। अब React Testing Library को सुझाया जाता है।
'implementation' की जगह 'behavior' की testing का क्या मतलब है?
Implementation testing (Enzyme) code की अंदरूनी details देखती है। Behavior testing (React Testing Library) इस पर ध्यान देती है कि end-user स्क्रीन पर क्या देखता है और application के साथ कैसे बातचीत करता है।
क्या मेरे सारे पुराने Enzyme tests सीधे बदले जा सकते हैं?
पूरी तरह नहीं। क्योंकि तरीका अलग है (behavior बनाम implementation), इसलिए जो पुराने tests अंदरूनी details जाँचते थे, उनका सीधा अनुवाद नहीं होगा। आपको उन्हें दिखने वाले परिणाम जाँचने के लिए फिर से लिखना होगा।
जानकारी
लेखक का मूल विवरण
Provides exact Enzyme → React Testing Library migration patterns for React 18 upgrades. Use this skill whenever Enzyme tests need to be rewritten - shallow, mount, wrapper.find(), wrapper.simulate(), wrapper.prop(), wrapper.state(), wrapper.instance(), Enzyme configure/Adapter calls, or any test file that imports from enzyme. This skill covers the full API mapping and the philosophy shift from imp
repo: github/awesome-copilot
लोकप्रियता
- GitHub स्टार
- 40k
- रैंकिंग में स्थान
- #7385
- लाइसेंस
- 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 पास कर सकें।