Find component by display name when the component is stateless functional, with Enzyme

This page summarizes the projects mentioned and recommended in the original post on /r/codehunter

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • tape

    tap-producing test harness for node and browsers

  • Reactjs I have the following components: // Hello.jsexport default (React) => ({name}) => { return ( Hello {name ? name : 'Stranger'}! )}// App.jsimport createHello from './Hello'export default (React) => () => { const Hello = createHello(React) const helloProps = { name: 'Jane' } return ( )}// index.jsimport React from 'react'import { render } from 'react-dom'import createApp from './App'const App = createApp(React)render( , document.getElementById('app')) And I want to set up a test to see if the App component contains one Hello component. I tried the following, using Tape and Enzyme: import createApp from './App'import React from 'react'import test from 'tape'import { shallow } from 'enzyme'test('App component test', (assert) => { const App = createApp(React) const wrapper = shallow() assert.equal(wrapper.find('Hello').length === 1, true)}) But the result was that the length property of the find result was equal to 0, when I was expecting it to be equal to 1. So, how do I find my Hello component? Answer link : https://codehunter.cc/a/reactjs/find-component-by-display-name-when-the-component-is-stateless-functional-with-enzyme

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts