我有一个使用Link,IndexLink来渲染导航栏的导航组件:
class Navigation extends Component {
renderLinks = (linksData) => {
return linksData.map((link) => {
if(link.to === '/') {
return (
{link.icon}
{link.text}
);
} else {
return (
{link.icon}
{link.text}
);
}
});
};
render() {
const {links} = this.props;
return(
{this.renderLinks(links)}
)
}
}
Navigation.propTypes = {
links: React.PropTypes.array.isRequired
}
export default Navigation;
现在我想测试我的链接是否正确呈现:
import React from 'react';
import {Link, IndexLink} from 'react-router';
import {mount} from 'enzyme';
import Navigation from '../components/core/Navigation.component';
describe(' ', () => {
it('should render Navigation links', () => {
const links = [
{
to: '/',
icon: 'hourglass_empty',
text: 'Timer'
}
];
const navigation = mount();
console.log(navigation.find('a').prop('href'));
});
});
但这只是注销未定义.我怎么能测试正确的href值是否传递给我的锚点?
尝试这个:
wrapper.find(Foo).at(0).props().href