I am trying to test a menu bar, which handles routing to some pages using history.push
. I am using Primereact Menubar component.
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)
How can I verify that when I click on a menubar button, it takes me to the correct page?
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/>)
//??
})
})