You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@cfaester/enzyme-adapter-react-18

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cfaester/enzyme-adapter-react-18

An unofficial React 18 adapter for Enzyme, that you probably shouldn't use.

0.8.0
latest
Source
npmnpm
Version published
Weekly downloads
183K
-23.13%
Maintainers
1
Weekly downloads
 
Created

What is @cfaester/enzyme-adapter-react-18?

@cfaester/enzyme-adapter-react-18 is an adapter for Enzyme that allows it to work with React 18. Enzyme is a JavaScript testing utility for React that makes it easier to assert, manipulate, and traverse your React Components' output.

What are @cfaester/enzyme-adapter-react-18's main functionalities?

Mounting Components

This feature allows you to mount a React component and inspect its rendered HTML. The `mount` function fully renders the component into the DOM.

const Enzyme = require('enzyme');
const Adapter = require('@cfaester/enzyme-adapter-react-18');
Enzyme.configure({ adapter: new Adapter() });

const React = require('react');
const { mount } = require('enzyme');

function MyComponent() {
  return <div>Hello, World!</div>;
}

const wrapper = mount(<MyComponent />);
console.log(wrapper.html()); // <div>Hello, World!</div>

Shallow Rendering

This feature allows you to shallow render a React component, which means only the component itself is rendered, not its children. This is useful for unit testing.

const Enzyme = require('enzyme');
const Adapter = require('@cfaester/enzyme-adapter-react-18');
Enzyme.configure({ adapter: new Adapter() });

const React = require('react');
const { shallow } = require('enzyme');

function MyComponent() {
  return <div>Hello, World!</div>;
}

const wrapper = shallow(<MyComponent />);
console.log(wrapper.html()); // <div>Hello, World!</div>

Finding Elements

This feature allows you to find elements within a mounted or shallow-rendered component. You can use CSS selectors to locate elements and then inspect or interact with them.

const Enzyme = require('enzyme');
const Adapter = require('@cfaester/enzyme-adapter-react-18');
Enzyme.configure({ adapter: new Adapter() });

const React = require('react');
const { mount } = require('enzyme');

function MyComponent() {
  return (
    <div>
      <span className="greeting">Hello, World!</span>
    </div>
  );
}

const wrapper = mount(<MyComponent />);
const span = wrapper.find('.greeting');
console.log(span.text()); // Hello, World!

Other packages similar to @cfaester/enzyme-adapter-react-18

Keywords

enzyme

FAQs

Package last updated on 29 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts