Angular error running Karma tests: HTML5 mode requires a <base> tag

后端 未结 3 1627
南笙
南笙 2020-12-06 04:29

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:<

3条回答
  •  醉话见心
    2020-12-06 04:55

    If you can't or do not want to set requireBase to false, the solution - as others pointed out - is to add 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.

提交回复
热议问题