Title: TestBed: rethink interactions with the @Input / @output of the root component · Issue #12313 · angular/angular · GitHub
Open Graph Title: TestBed: rethink interactions with the @Input / @output of the root component · Issue #12313 · angular/angular
X Title: TestBed: rethink interactions with the @Input / @output of the root component · Issue #12313 · angular/angular
Description: I'm submitting a ... (check one with "x") [x] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support request here, instead see https://github.com/an...
Open Graph Description: I'm submitting a ... (check one with "x") [x] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support request...
X Description: I'm submitting a ... (check one with "x") [x] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not su...
Opengraph URL: https://github.com/angular/angular/issues/12313
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TestBed: rethink interactions with the @Input / @output of the root component","articleBody":"**I'm submitting a ...** (check one with \"x\")\n\n```\n[x] bug report => search github for a similar issue or PR before submitting\n[ ] feature request\n[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\n```\n\nTBH I'm not sure if this is a bug, a feature request, or just a product of my ignorance/incomplete docs.\n\n**Current behavior**\n\nWhen I have a component using `ChangeDetectionStrategy.OnPush`, I can create a test fixture via `const fixture = TestBed.createComponent(TestComponent)` but can't figure out how to force a change detection after altering one of the input properties. Just calling `fixture.detectChanges()` like I would for a `ChangeDetectionStrategy.Default` component doesn't seem to do it. I've also tried in conjunction with `fixture.changeDetectorRef.markForCheck()` but still no luck. However, if I wrap my OnPush component in another component for testing purposes, it works as expected.\n\n**Expected behavior**\n\nShould be some way to force a change detection on a OnPush component when changing its inputs directly via the component fixture (rather than via a wrapper component).\n\n**Minimal reproduction of the problem with instructions**\n\ntest.component:\n\n``` typescript\nimport { Component, Input, ChangeDetectionStrategy } from '@angular/core';\n\n@Component({\n selector: 'my-test',\n template: '\u003cp>{{ content }}\u003c/p>',\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class TestComponent {\n @Input() content: string;\n}\n```\n\ntest.component.spec.ts (this test fails w/ OnPush but passes with Default):\n\n``` typescript\nimport { TestBed } from '@angular/core/testing';\nimport { By } from '@angular/platform-browser';\nimport { TestComponent } from './test.component';\n\ndescribe('Test Component', () => {\n beforeEach(() => {\n TestBed.configureTestingModule({declarations: [TestComponent]});\n });\n it('should render the bound content within a p element', () => {\n const fixture = TestBed.createComponent(TestComponent);\n fixture.detectChanges();\n const p = fixture.debugElement.query(By.css('p'));\n expect((p.nativeElement as HTMLParagraphElement).innerText).toBeFalsy();\n fixture.componentInstance.content = 'Test!';\n fixture.detectChanges();\n expect((p.nativeElement as HTMLParagraphElement).innerText).toEqual('Test!');\n });\n});\n```\n\ntest.component.wrapped.spec.ts (this passes with OnPush or Default):\n\n``` typescript\nimport { Component } from '@angular/core';\nimport { TestBed } from '@angular/core/testing';\nimport { By } from '@angular/platform-browser';\nimport { TestComponent } from './test.component';\n\n@Component({\n selector: 'my-wrapper',\n template: '\u003cmy-test [content]=\"content\">\u003c/my-test>'\n})\nclass WrapperComponent {\n content: string;\n}\ndescribe('Test Component (Wrapped)', () => {\n beforeEach(() => {\n TestBed.configureTestingModule({declarations: [TestComponent, WrapperComponent]});\n });\n\n it('should render the bound content within a p element', () => {\n const fixture = TestBed.createComponent(WrapperComponent);\n fixture.detectChanges();\n const p = fixture.debugElement.query(By.css('p'));\n expect((p.nativeElement as HTMLParagraphElement).innerText).toBeFalsy();\n fixture.componentInstance.content = 'Test!';\n fixture.detectChanges();\n expect((p.nativeElement as HTMLParagraphElement).innerText).toEqual('Test!');\n });\n});\n```\n\n**What is the motivation / use case for changing the behavior?**\n\nWould prefer to use roughly the same testing patterns regardless of which change detection strategy I'm using. \n\n**Please tell us about your environment:**\n- **Angular version:** 2.1.0\n- **Browser:** all\n- **Language:** TS 2.0.3\n","author":{"url":"https://github.com/mattdistefano","@type":"Person","name":"mattdistefano"},"datePublished":"2016-10-14T17:44:02Z","url":"https://github.com/angular/angular/issues/12313"}
| 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:412241c3-e4ce-d7e5-b0bd-e81c0bcac9e9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8F2C:14F601:E0363B:11FC955:6B00F3FC |
| html-safe-nonce | 6760df87ec0b05aa0f4f1bfcf0cf5712f3ebb0e9322a548413f4e1e3c2a677c3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RjJDOjE0RjYwMTpFMDM2M0I6MTFGQzk1NTo2QjAwRjNGQyIsInZpc2l0b3JfaWQiOiI4MTIyOTQ5MzAyMjgxNjMwNzE3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a81e9bd2bab002aa328cdccbbde4c5fd886df0a64e1e2c6a846fa15c02551017 |
| hovercard-subject-tag | issue:183109642 |
| 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/12313/issue_layout |
| twitter:image | https://opengraph.githubassets.com/830e04150774d673e07bda9a88bbb99d1ce7b30a62b20c8e8e13bb96b36a4dcb/angular/angular/issues/12313 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/830e04150774d673e07bda9a88bbb99d1ce7b30a62b20c8e8e13bb96b36a4dcb/angular/angular/issues/12313 |
| og:image:alt | I'm submitting a ... (check one with "x") [x] bug report => search github for a similar issue or PR before submitting [ ] feature request [ ] support request => Please do not submit support request... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mattdistefano |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width