-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: This method is only meant to be run on single node. 0 found instead. #184
Comments
Which line does the error come from? |
@cameronroe try outputting |
Looks like my project was reactjs_koans had duplicate folders and I was editing in the wrong one. No problems. Apologies for that. |
I still have no idea whats going on here:
|
@ccorcos can you share your test case that's throwing this error? |
figured it out:
we're not in HTML land. I'm just geting the hang of enzyme. |
I get this error with the following in my test, and no
The error happens because no header is found, so hasClass() blows up. I would really appreciate a more meaningful error message that doesn't force me to google it to figure out what the heck it's talking about. That said, now that I understand it, I can understand why this would be difficult to do....... A start might be instead of "this method" give the name of the method. ie. "'hasClass' is only meant..." For an uninitiated this would keep from thinking that the it's an internal problem -- my original thought was "oh no... just my luck. Something's going on and one of the internal rendering nodes (processes) can't start up and I have no idea how to debug this". Another thought is to have find() error if the element(s) can't be found. Since that would break the existing API, and make it so that negative tests would fail, maybe a second parameter of Just throwing out ideas here for discussion. |
@emragins is the message "0 found instead" not clear that no header is found? |
It is once I understand the context in which the error is being thrown. I feel like it would be more intuitive if the message were changed to help me find that context by adding the function call in question. As indicated, I'm very very new to enzyme and my initial reaction to the message was way off-base. I guess my feeling is that with it being a developer tool, any "leg up" to help the developer diagnose the issue is a good thing. |
I definitely agree it'd be a great improvement for the error message to contain the method that threw. |
erm what happened to this, I have the same error and it still appears vague? |
@jpmelnik @marcfielding1 would you both mind filing separate issues for your problem? |
Yeah sure, actually it's my own fault for being an idiot, I'd refactored some code to the wrapper pattern and was still using shallow(). To be fair I'm not sure what you guys could do about this, the error is actually correct, the problem is if you look at wrapper.html() it actually returns the component it's supposed to - but obviously if I shallow() and then try and work with the values from the sub component it blurts out the error. I think it's maybe a case of updating the docs to reflect this rather than a bug as such? Sorry if my comment yesterday was a bit terse I'd been rather rushing around all day :-) |
I'm getting this same problem. I'm trying to test the onDateChange prop of the react-dates SingleDatePicker, and it thinks I have 0 nodes. Here's an excerpt of my component file: export default class ExpenseForm extends React.Component {
onDateChange = (createdAt) => {
if (createdAt){
this.setState(() => ({ createdAt }));
}
};
render() {
return (
<div>
<SingleDatePicker
date={this.state.createdAt}
onDateChange={this.onDateChange}
focused={this.state.calendarFocused}
onFocusChange={this.onFocusChange}
/>
</div>
)
}
} And here's the test: test('test should set new date on date change', () => {
const now = moment();
const wrapper = shallow(<ExpenseForm />);
wrapper.find('SingleDatePicker').prop('onDateChange')(now);
expect(wrapper.state('createdAt')).toEqual(now);
}); As the issue title states, it gives me the message, Edit: After more testing, this seems to be an issue specific to react-dates. react-dates has three components, |
@BennyHinrichs finding with a string is very brittle; in this case, while |
I wasn't sure what you meant by trying to find with a reference instead but after a lot of trial and error / googling around I found out that I could select the element using
I found the actual display name by digging through the React Chrome extension and finding out it's exact name. Though this doesn't seem like a good solution. Have you found a better one? |
@BennyHinrichs @sanyangkkun - I believe what @ljharb meant is that instead of using the form - |
Just to add to @revik . SingleDatePicker should be imported as well.
|
please, i am having the same issue, do i need to setup anything before being able to use the simulate method? |
here is my test case : it("it should call the handleAnswer method correctly", () => { |
and here is the error from the terminal:
|
@chisom5 "badge" should be an inner element (or component) inside your Badge component, error indicates that it is not finding the element correctly in order to simulate a click on it |
Thanks @dori871992 will check that out |
i am also getting the same problem and i am getting the error is |
I got the same error it("should handle date changes", () => {
const startDate = moment(0).add(4, "years");
const endDate = moment(0).add(8, "years");
wrapper.find("withStyles(DateRangePicker)").prop("onDatesChange")({ startDate, endDate });
expect(setStartDateSpy).toHaveBeenLastCalledWith(startDate);
expect(setEndDateSpy).toHaveBeenLastCalledWith(endDate);
}); |
@simoneas02 alternatively/better, you could |
I am also getting error similar to this. Please help me to resolve this. Test case
Component
Error Getting is FAIL src/tests/Profile.test.js
|
Do anyone help me on this?? getting error |
@Mercy-1998 use the |
` Method “props” is meant to be run on 1 node. 0 found instead.
` |
@Mercy-1998 again, change your code so you're passing the |
` Method “props” is meant to be run on 1 node. 0 found instead.
` is this right for 'redirect' tag? |
I got it |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I started getting this error after I updated react-redux from ^5.0.7 to ^7.2.2. I needed to upgrade so that I could use the functions useSelector, and useDispatch. Does anyone know how this could be related to the version of the library? |
Any solution for this? Am stuck here too,,wrapper.html() has content but wrapper.find() cant find any elements |
@AlbogastAman try .debug() - .html calls cheerio via render, which won’t give you an accurate picture. |
Thanks for the response @Ijharb,i have tried .debug() but i cant figure out the problem out of .debug() |
Looks like you need at least one .dive() - you need one per HOC. |
Good morning everyone I am using jest and enzyme to check the Please I need your helps thank you in advance describe("Login Page", () => {
} |
Note you can omit the image where the describe() method is |
Span is a tag name, not a class; remove the leading dot. |
Thanks I removed it and put the dot infront and added the class name but still I am having the same error |
You have a space there and “p-b-53” which isn’t a valid tag name. Perhaps that space is meant to be a dot also? |
even after removing p-b-53 that is bootstrap part I am still having this " Method “text” is meant to be run on 1 node. 0 found instead." |
No, I’m sure it’s another typo. Can you please file a new issue with full component and test code? |
Clearly rendering a node. It's not picking it up..?
The text was updated successfully, but these errors were encountered: