我正在尝试测试一个菜单栏,该菜单栏使用history.push
. 我正在使用 Primereact 菜单栏组件。
class MenubarComponent extends React.Component {
constructor() {
super();
this.state = {
items: [
{
label: "Home",
icon: "pi pi-home",
command: () => (this.props.history.push("/"))
},
{
label: "About",
icon: "pi pi-info",
command: () => (this.props.history.push("/about"))
}
]
}
}
render() {
return (
<Menubar model={this.state.items}/>
)
}
}
export default withRouter(MenubarComponent)
如何验证当我单击菜单栏按钮时,它会将我带到正确的页面?
describe('MenubarComponent', () => {
it('should navigate on menuitem click', () => {
const menubarItemsMock = jest.fn();
const item = {
label: "Home",
icon: "pi pi-home",
command: () => (this.props.history.push("/"))
}
const wrapper = shallow(<MenubarComponent/>)
//??
})
})