-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[router/testing] No base href set
errors in tests appear with router when using Debug Mode
#19116
Closed
1 of 15 tasks
Labels
area: @angular-devkit/build-angular
devkit/build-angular:karma
freq1: low
Only reported by a handful of users who observe it rarely
severity3: broken
type: bug/fix
Milestone
Comments
IxquitilisSaid
added a commit
to IxquitilisSaid/angular-cli
that referenced
this issue
Oct 19, 2020
…ntext This commits adds a base href value in the karma context iframe used to run unit tests where a unit test throws: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document. Even if the application is fine. This is because the index.html from Angular CLI contains a base href value, but not the Karma context iframe. So when adding a unit test with a testing module that imports a NgModule, for example AppModule, which itself imports RouterModule, the unit test used to throw an error (regression appeared in router 3.1). That could be solved by either adding `RouterTestingModule` to the testing module, or by adding a provider `{ provide: APP_BASE_HREF, useValue: '/' }`, but required to understand the issue. This solves the issue in a transparent way: developers won't even encounter the problem anymore. Closes angular#19116
alan-agius4
pushed a commit
that referenced
this issue
Oct 19, 2020
…ntext This commits adds a base href value in the karma context iframe used to run unit tests where a unit test throws: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document. Even if the application is fine. This is because the index.html from Angular CLI contains a base href value, but not the Karma context iframe. So when adding a unit test with a testing module that imports a NgModule, for example AppModule, which itself imports RouterModule, the unit test used to throw an error (regression appeared in router 3.1). That could be solved by either adding `RouterTestingModule` to the testing module, or by adding a provider `{ provide: APP_BASE_HREF, useValue: '/' }`, but required to understand the issue. This solves the issue in a transparent way: developers won't even encounter the problem anymore. Closes #19116 (cherry picked from commit ae94245)
alan-agius4
pushed a commit
that referenced
this issue
Oct 19, 2020
…ntext This commits adds a base href value in the karma context iframe used to run unit tests where a unit test throws: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document. Even if the application is fine. This is because the index.html from Angular CLI contains a base href value, but not the Karma context iframe. So when adding a unit test with a testing module that imports a NgModule, for example AppModule, which itself imports RouterModule, the unit test used to throw an error (regression appeared in router 3.1). That could be solved by either adding `RouterTestingModule` to the testing module, or by adding a provider `{ provide: APP_BASE_HREF, useValue: '/' }`, but required to understand the issue. This solves the issue in a transparent way: developers won't even encounter the problem anymore. Closes #19116 (cherry picked from commit ae94245)
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
area: @angular-devkit/build-angular
devkit/build-angular:karma
freq1: low
Only reported by a handful of users who observe it rarely
severity3: broken
type: bug/fix
🐞 Bug report
Is this a regression?
No. Seems to me that it's a pretty old issue.
Description
In short, when testing an app with routing, tests will run fine unless you toggle Karma's debug mode. There all components with routing will throw the aforementioned "No base href set" error.
🔬 Minimal Reproduction
I've made a demo repo for it here
Initially, all the tests will be green and succeed but if you click the
Debug
button above, you'll see the error being thrown🔥 Exception or Error
🌍 Your Environment
The text was updated successfully, but these errors were encountered: