This test returns this error no matter what I do, including rewriting this file 10 different ways and using different methods in enzyme:
Method “props” is only meant to be run on a single node. 0 found instead.
Stack trace:
```
ShallowWrapper.single (node_modules\enzymebuild\ShallowWrapper.js:1473:17)
at ShallowWrapper.props (node_modules\enzymebuild\ShallowWrapper.js:826:21)
at ShallowWrapper.prop (node_modules\enzymebuild\ShallowWrapper.js:1032:21)
at Object.it (src\SortTodos.test.js:34:43)
at process._tickCallback (internal\process\next_tick.js:103:7)
Test file:
```import React from 'react';
import { shallow, render } from 'enzyme';
import SortTodos from './SortTodos';
describe('name', () => {
const wrapper = shallow(
<SortTodos
sortByName={()=> {}}
sortByRecency={()=>{}}
selectedBTN={{}}
/>
);
it('renders .SelectedBTN class when name button clicked', () => {
wrapper.setProps({selectedBTN: {name:true, recency:false}});
expect(wrapper.find('#sortByName').prop('className')).toEqual('SelectedBTN');
});
});
describe('recency', () => {
const wrapper = shallow(
<SortTodos
sortByName={()=> {}}
sortByRecency={()=>{}}
selectedBTN={{}}
/>
);
it('renders .SelectedBTN class when name button clicked', () => {
wrapper.setProps({selectedBTN: {name:false, recency:true}});
// THIS LINE BELOW IS LINE 34, CAUSING THE ERROR
expect(wrapper.find('#sortByRecency').prop('className')).toEqual('SelectedBTN');
});
});
SortTodos.js
import React from 'react';
import './SortTodos.css';
function SortTodos({ sortByName, sortByRecency, selectedBTN }) {
return(
<div id="SortBy">
Sort By:
<button id="sortByName" onClick={sortByName} className={selectedBTN.name ? "SelectedBTN" :""}>Name</button>
<button id="sortByDate" onClick={sortByRecency} className={selectedBTN.recency ? "SelectedBTN" :""}>Recency</button>
</div>
)
}
SortTodos.propTypes = {
sortByName: React.PropTypes.func.isRequired,
sortByRecency: React.PropTypes.func.isRequired,
selectedBTN: React.PropTypes.object.isRequired
};
export default SortTodos;
Thanks for any help.
You're finding by an ID named "sortByRecency" but you only have "sortByName" and "sortByDate", so it's finding nothing.
Thanks. Whoops ;)
Most helpful comment
You're finding by an ID named "sortByRecency" but you only have "sortByName" and "sortByDate", so it's finding nothing.