I have a navigation component that uses Link, IndexLink to render the navigation bar:
class Navigation extends Component {
renderLinks = (linksData) => {
return linksData.map((link) => {
if(link.to === '/') {
return (
<li key={link.text}>
<IndexLink to={link.to}>
<i>{link.icon}</i>
<span>{link.text}</span>
</IndexLink>
</li>
);
} else {
return (
<li key={link.text}>
<Link to={link.to}>
<i>{link.icon}</i>
<span>{link.text}</span>
</Link>
</li>
);
}
});
};
render() {
const {links} = this.props;
return(
<div>
<ul>
{this.renderLinks(links)}
</ul>
</div>
)
}
}
Navigation.propTypes = {
links: React.PropTypes.array.isRequired
}
export default Navigation;
Now I want to test that my links render correcttly:
import React from 'react';
import {Link, IndexLink} from 'react-router';
import {mount} from 'enzyme';
import Navigation from '../components/core/Navigation.component';
describe('<Navigation/>', () => {
it('should render Navigation links', () => {
const links = [
{
to: '/',
icon: 'hourglass_empty',
text: 'Timer'
}
];
const navigation = mount(<Navigation links={links}/>);
console.log(navigation.find('a').prop('href'));
});
});
But this just logs out undefined. How am I able to test that the correct href value is getting passed to my anchors?