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

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 पढ़कर निर्देशों का पालन करेगा।

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

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

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, configure
  • references/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)

  1. getByRole - matches accessible roles (button, textbox, heading, checkbox, etc.)
  2. getByLabelText - form fields linked to labels
  3. getByPlaceholderText - input placeholders
  4. getByText - visible text content
  5. getByDisplayValue - current value of input/select/textarea
  6. getByAltText - image alt text
  7. getByTitle - title attribute
  8. getByTestId - data-testid attribute (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

क्या यह 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