'Unit Test - Simulate click not fired and location not changing (React / React-router)

I have a toolbar, with a logo and title, on which you can click to go back to the home page.

I try to unit test the click on this, but it seems it's not fired and the location is not changed.

Here's the component's code:

<AppBar position="static">
        <Toolbar>
            <img
                src='./src/assets/logo.svg'
                className={classes.logo}
                onClick={() => history.push('/home')}
            />
            <Typography onClick={() => history.push('/home')}>
                Demo Project
            </Typography>
    </AppBar>

And here the Unit Test i'm trying to do:

it('should go back home', () => {
        let testLocation;

        const component = mount(
            <MemoryRouter initialEntries={['/landscape']}>
                <AppBar />
                <Switch>
                    <Route
                        path="*"
                        render={({ history, location }) => {
                            testLocation = location;
                            return null;
                        }}
                    />
                </Switch>
            </MemoryRouter>,
        );

        expect(testLocation.pathname).toBe('/landscape');

        const logo = component.find('img');
        logo.simulate('click');

        expect(testLocation.pathname).toBe('/home');
    });

I receive this error:

expect(received).toBe(expected) // Object.is equality

Expected: "/home"
Received: "/landscape"

Does anyone have an idea of what's going wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source