I have a single-page Angular app with a Rails backend. I am using a tag in my index.html
file, but when I run my front-end unit tests using Karma, I get this:<
You can disable the base tag check by doing the following:
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
You can specify your base tag in your index.html <head>
like that:
<head>
<base href="/">
...
</head>
Source: from angularjs documentation
If you can't or do not want to set requireBase
to false
, the solution - as others pointed out - is to add <base href="/">
in the header of your primary HTML file. To do this, you will need to specify custom HTML files for Karma, which you can then edit.
First find and copy node_modules/karma/static/context.html
and node_modules/karma/static/debug.html
to your unit test folder, and amend the headers of both.
Then in your karma.conf.js add the following two lines:
customContextFile: 'test/unit/context.html',
customDebugFile: 'test/unit/debug.html',
Of course your path may vary.