Mock basename in Jest / Enzyme

You can always mock out the url from within your Jest config.

My approach generally is including this within my package.json

In your case, I would expect this to be something like -

 "jest": {
    "testURL": "http://some-domain.tld/admin"
  }

You can then change this on a per test basis by including the following in your beforeEach() block

window.history.pushState({}, 'Foo Title', '/admin/foo');

For those using create-react-app: update package.json and add the url at the end of the test command line like this:

react-scripts-ts test --env=jsdom --watch --testURL http://localhost/foo

Source: https://github.com/facebook/create-react-app/issues/3425