Title: "Navigation triggered outside Angular zone" warning in unit tests · Issue #25837 · angular/angular · GitHub
Open Graph Title: "Navigation triggered outside Angular zone" warning in unit tests · Issue #25837 · angular/angular
X Title: "Navigation triggered outside Angular zone" warning in unit tests · Issue #25837 · angular/angular
Description: I'm submitting a... [x] Regression (a behavior that used to work and stopped working in a new release) [ ] Bug report [ ] Performance issue [ ] Feature request [ ] Documentation issue or request [ ] Support request => Please do not submi...
Open Graph Description: I'm submitting a... [x] Regression (a behavior that used to work and stopped working in a new release) [ ] Bug report [ ] Performance issue [ ] Feature request [ ] Documentation issue or request [ ...
X Description: I'm submitting a... [x] Regression (a behavior that used to work and stopped working in a new release) [ ] Bug report [ ] Performance issue [ ] Feature request [ ] Documentation issue or reques...
Opengraph URL: https://github.com/angular/angular/issues/25837
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"\"Navigation triggered outside Angular zone\" warning in unit tests","articleBody":"## I'm submitting a...\r\n\u003c!-- Check one of the following options with \"x\" -->\r\n\u003cpre>\u003ccode>\r\n[x] Regression (a behavior that used to work and stopped working in a new release)\r\n[ ] Bug report \u003c!-- Please search GitHub for a similar issue or PR before submitting -->\r\n[ ] Performance issue\r\n[ ] Feature request\r\n[ ] Documentation issue or request\r\n[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\r\n[ ] Other... Please describe:\r\n\u003c/code>\u003c/pre>\r\n\r\n## Current behavior\r\n\r\nUsing the last Angular `6.1.7` which introduced a warning if a navigation is triggered outside a zone (see https://github.com/angular/angular/commit/010e35d99596e1b35808aaaeecfc32f3b247a7d8),\r\na simple unit test calling `router.navigate` yields the warning (resulting in hundreds of warnings in the console).\r\n\r\n\r\n## Expected behavior\r\n\r\nThe warning should not be emitted in unit tests.\r\nIt's currently possible to remove it by using `zone.run` or using `NoopNgZone`, but this is cumbersome. A way to disable it in unit tests would be great.\r\n\r\n\r\n## Minimal reproduction of the problem with instructions\r\n\r\nBuild a minimal app with the CLI\r\n\r\n```\r\nng new router-warning --routing\r\n```\r\n\r\nThen replace the default unit test with:\r\n\r\n```typescript\r\nimport { TestBed, async } from '@angular/core/testing';\r\nimport { RouterTestingModule } from '@angular/router/testing';\r\nimport { Router } from '@angular/router';\r\n\r\nimport { AppComponent } from './app.component';\r\n\r\ndescribe('AppComponent', () => {\r\n beforeEach(async(() => {\r\n TestBed.configureTestingModule({\r\n imports: [\r\n RouterTestingModule\r\n ],\r\n declarations: [\r\n AppComponent\r\n ],\r\n }).compileComponents();\r\n }));\r\n\r\n it('should create the app', async(() => {\r\n const router = TestBed.get(Router) as Router;\r\n router.navigateByUrl('/');\r\n const fixture = TestBed.createComponent(AppComponent);\r\n const app = fixture.debugElement.componentInstance;\r\n expect(app).toBeTruthy();\r\n }));\r\n});\r\n```\r\n\r\nRun `ng test`, and the following warning should appear:\r\n\r\n```\r\nWARN: 'Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()'?'\r\n```\r\n\r\n## Environment\r\n\r\n\u003cpre>\u003ccode>\r\nAngular version: 6.1.7 or 7.0.0-beta.5\r\n\r\nBrowser:\r\n- [x] Chrome (desktop) version XX\r\n- [ ] Chrome (Android) version XX\r\n- [ ] Chrome (iOS) version XX\r\n- [ ] Firefox version XX\r\n- [ ] Safari (desktop) version XX\r\n- [ ] Safari (iOS) version XX\r\n- [ ] IE version XX\r\n- [ ] Edge version XX\r\n \r\nFor Tooling issues:\r\n- Node version: 8.11.3\r\n- Platform: Mac\r\n\r\n\u003c/code>\u003c/pre>\r\n\r\ncc @trotyl ","author":{"url":"https://github.com/cexbrayat","@type":"Person","name":"cexbrayat"},"datePublished":"2018-09-06T07:33:12Z","url":"https://github.com/angular/angular/issues/25837"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0c57164a-533c-d003-719c-4ed4ddfd04bf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9388:3C21B:183DEF5:1F02D92:6B0130B7 |
| html-safe-nonce | b08db7705f6a0847d3b1eb97b67c02a1bb2b9968ff6815ba22f9c41cc2edbf5b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Mzg4OjNDMjFCOjE4M0RFRjU6MUYwMkQ5Mjo2QjAxMzBCNyIsInZpc2l0b3JfaWQiOiI3OTQxMDE3NjgzMDc4NzU0NDg3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c69ca5416987eda3f4d7afc77b35783044c1221085e3326f1ae1fa889e87878f |
| hovercard-subject-tag | issue:357530468 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/25837/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c9c88b628b4f5c044bd35125eae79a4e75a18d2f9acdb22722303332f5a0acd6/angular/angular/issues/25837 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c9c88b628b4f5c044bd35125eae79a4e75a18d2f9acdb22722303332f5a0acd6/angular/angular/issues/25837 |
| og:image:alt | I'm submitting a... [x] Regression (a behavior that used to work and stopped working in a new release) [ ] Bug report [ ] Performance issue [ ] Feature request [ ] Documentation issue or request [ ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cexbrayat |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width