Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 14 15:37
    ljharb commented #2524
  • Jun 12 17:09
    renovate[bot] edited #2497
  • Jun 12 00:22
    ljharb commented #1229
  • Jun 11 14:43
    ZeCarlosCoutinho commented #1229
  • Jun 11 14:42
    ZeCarlosCoutinho commented #1229
  • Jun 10 21:11
    wojtekmaj commented #2430
  • Jun 10 09:41
    TeoTN opened #2524
  • Jun 09 20:33
    ljharb labeled #2522
  • Jun 09 20:33
    ljharb closed #2522
  • Jun 09 20:33
    ljharb commented #2522
  • Jun 09 19:44
    ljharb labeled #2523
  • Jun 09 19:44
    ljharb commented #2523
  • Jun 09 19:42
    ljharb commented #2523
  • Jun 09 19:39
    Whoaa512 edited #2523
  • Jun 09 19:39
    Whoaa512 opened #2523
  • Jun 09 19:33
    ljharb commented #2429
  • Jun 09 19:30
    lucasgcb commented #2429
  • Jun 09 19:05
    ljharb commented #2429
  • Jun 09 17:35
    lucasgcb commented #2429
  • Jun 09 14:27
    ljharb commented #2522
Jordan Harband
@ljharb
react doesn't provide hooks for hooks
so you can't use shallow, with a react-redux version that uses hooks, at least not out of the box
Tomek Kasperek
@kasperekt
Okay. Cool. So for now there is no resolution for this right, other than downgrading to earlier versions
duolingo-appearance
@duolingo-appearance
Does anyone have a clue about this issue, enzymejs/enzyme#2415
Hardik Kaji
@hardikkaji
Hello 👋 , I am facing issue with mount with MobX observer component.
it's throwing below error.
 ✖ should render properly
      HeadlessChrome 83.0.4103 (Mac OS X 10.15.6)
    Error: Enzyme Internal Error: unknown node with tag 15

describe("<SomeComponent />", function () {
    it("should render properly", function () {
        const component = mount(
            <StoreProvider>
                <SomeComponent />
            </StoreProvider>
        );
    });
});
The error comes when i wrap my component with observer(SomeComponent)
afeel87
@afeel87
Hello, I am facing issue with the shallow
const props = {
intl: { formatMessage: jest.fn() },
resetFormAction: jest.fn(),
history: jest.fn()
};
let instance = null;

beforeEach(() => {
    instance = shallow(<NotificationView {...props}/>);
});

it('should render the notification component', () => {
    expect(instance.exists()).toEqual(true);
});

it('should find the elements of the notification component', () => {

    const notification = instance.find(Notification);
    const notificationActionBar = instance.find(NotificationActionBar);

    expect(notification.exists()).toBe(true);
    expect(notificationActionBar.exists()).toBe(true);
}); 
TypeError: Enzyme::Selector expects a string, object, or Component Constructor
Jordan Harband
@ljharb
the implication is that either Notification or NotificationActionBar is not actually a component constructor.
try console.logging them and confirm
hybaken
@hybaken

Hi, I am new to enzyme.
I am trying to test my functional component, but shallow returns me always null. Any idea where I should look at?

const wrapper = shallow(<MyComponent />);

I do have set adapter in setupTest.js (app created with create-react-app)

import '@testing-library/jest-dom/extend-expect';
import { configure } from "enzyme";
import Adapter from "enzyme-adapter-react-16";

configure({ adapter: new Adapter() });

I have tried to shallow on direct html element and this works fine.

const wrapper = shallow(<div >test</div>);

For check I use

 console.log(wrapper.first().html())
2 replies
Abhishek Singh
@asingh04
Hi I am stuck with something, can anyone help me out?
I am calling a member function of a class component using enzyme in a unit test, and that function calls thethis.setState
but the state of my component is not updating
Abhishek Singh
@asingh04
class MyComp extends React.Component {
    state = { value: '' }
    handleChange = (e) => {
        this.setState({ value: e.target.value }, () => {
            // do sommething else
        });
    }

    render() {
        return (
            <input onChange={ this.handleChange } />
        )
    }
}

const wrapper = shallow(<MyComp />);

wrapper.find('input').simulate('change', {
    target: {
        value: 1,
        name: 0
    }
});

expect(wrapper.state().value).toEqual('1'); // this gives error as it is receiving state.value as ''
6 replies
Can anyone please help me understand why the component's internal setState is not working?
Jordan Harband
@ljharb
oh, well yeah
this.setState shouldn't be given an object, it should be given a callback
altho hm
that should work. but since you do handleChange =, instead of a proper bound prototype method, that means you also can't mock it out
(don't put functions in class fields)
Othniel
@Kojey
Hi everyone, I'm new to web development and I've started using enzyme a few days ago.
I am using mount to load a component into the DOM. One of its children is a Blueprint3.Select component whose value I want to change.
Unlike with shallow, I cannot use simulate on the react component to change its value which is wrapped in a <div>.
I have two questions:
  • Is there a way I can manipulate the DOM directly to set the value of the <div> of this component?
  • Can we use simulate on React component when using mount?
Jordan Harband
@ljharb
i wouldn't suggest using simulate ever
if you want to invoke a prop function, use .invoke
Othniel
@Kojey
@ljharb Thanks :)
Nick Artemov
@kerosan
hi all
do you know right way to test FunctionalComponent with useEffect/useCallback ?
Ashik Meerankutty
@ashikmeerankutty
hi everyone is there a way to use setSelectionRange for a textarea
Jenifer L.
@jelowing
Hi, Is anybody here?
I have a component wrapper with a Provider and store and I simulate a click event. I want to test that some state prop has change but nothing changes
Sergio
@Gio2k
hello, one question, is there already an adapter for react 17?
Jordan Harband
@ljharb
no, not yet. There’s an open issue to track it.
werner-jakobsmeier-thd
@werner-jakobsmeier-thd
Hi, I am having an issue with getting enzyme to work in our react 16 app:
Enzyme Internal Error: Enzyme expects an adapter to be configured, but found none.
Is there anyone who could get in touch with me, we seem to have exhausted all the references and SO related links and we just can not get it to work. Please :(
Jordan Harband
@ljharb
the docs describe configuring an adapter, have you done that?
werner-jakobsmeier-thd
@werner-jakobsmeier-thd
We tried, sorry for the late response.
We ended up abandoning Enzyme.
We were working in TS and just couldn't make it work.
Maybe you guys should reevaluate the docs because there are quite a few instances of people just not being able to get it to work.
Jordan Harband
@ljharb
lol, after 4 hours?
i'm happy to improve the doc, but afaik using TS doesn't change anything, and https://enzymejs.github.io/enzyme/docs/installation/ covers configuring the adapter
MOR NDIAYE
@Almorisson
Hello everyone. I'm new in Gitter. Hope to learn with the community and share knowlegde. if someone like to guide me through, i'm an I am an open-minded. Thanks in advance for your welcome
Roy
@iroy2000
I have a hard time testing lazy loading component using React.Suspense and React.lazy. I'm using "enzyme": "^3.10.3",. I'm wondering if that is supported or how would I test it ?
Jordan Harband
@ljharb
it should be supported, using the suspenseFallback option. try enzyme v3.11, and the latest adapter, just in case.
fabio-silva
@fabio-silva

Hey there. I'm facing an interesting problem that I can't figure out:
I got a form which I'm testing, so I get the submit button like this: button = wrapper.find('#notification-channel-add-button')
I then try so simulate a change event: input.simulate('change', { target: { value: 'Sample text' } })
Then, depending on how I test the disabled state of the button, I get different results:

// Correctly passes
expect(button.getDOMNode().hasAttribute('disabled')).toBeFalsy();

// This fails
expect(button.props().disabled).toBeFalsy();

Has anyone ever faced this problem?

Prafull37
@Prafull37
I have published my article on React check out . Give a clap and Share. Open for feedback
https://prafullsingh37.medium.com/react-is-easy-why-react-is-popular-a99d43288ce8
Rostislav Radionov
@radionov018
image.png
1 reply
Hello everyone!
Can anyone come across such a problem?
The component is static and don't have asynchronous logic
Jordan Harband
@ljharb
@radionov018 sorry, missed this here. enzyme doesn't support react 17 yet.