feat(core): add utility for testing directives - #70453
Conversation
ae60f3b to
074f531
Compare
Adds `TestBed.createDirective` to make testing directives easier. Fixes angular#54164.
074f531 to
7a2b0ac
Compare
| const noNgZone = this.inject(ComponentFixtureNoNgZone, false); | ||
| const ngZone = noNgZone ? null : this.inject(NgZone, null); |
There was a problem hiding this comment.
I think the way to do this so it matches fixture and app behavior is
const ngZone = this.inject(ComponentFixtureNoNgZone, false) ? new NoopNgZone() : inject(NgZone);
And then you can just do ngZone.run below without the separate init (done twice below)
There was a problem hiding this comment.
I was matching this to what we have for components.
There was a problem hiding this comment.
Oh, can we change it there too then? 馃槄 inject(NgZone) should really never fail
There was a problem hiding this comment.
In theory it could break if somebody was doing something like {provide: NgZone, useValue: null}, I can't imagine why but also wouldn't be surprised. I can do it in a follow-up so I don't need to re-TGP this change.
There was a problem hiding this comment.
In theory it could break if somebody was doing something like {provide: NgZone, useValue: null}, I can't imagine why but also wouldn't be surprised. I can do it in a follow-up so I don't need to re-TGP this change.
I don't think it's possible. In the constructor of ComponentFixture, it does this._ngZone.runOutsideAngular
There was a problem hiding this comment.
But I'm okay with you doing this as a followup
|
This PR was merged into the repository. The changes were merged into the following branches:
|
Since angular/angular#70453, the framework has a `DirectiveFixture` in addition to the `ComponentFixture`. These changes expand the APIs in the `TestbedHarnessEnvironment` to account for directive fixtures.
Since angular/angular#70453, the framework has a `DirectiveFixture` in addition to the `ComponentFixture`. These changes expand the APIs in the `TestbedHarnessEnvironment` to account for directive fixtures.
Since angular/angular#70453, the framework has a `DirectiveFixture` in addition to the `ComponentFixture`. These changes expand the APIs in the `TestbedHarnessEnvironment` to account for directive fixtures.
Since angular/angular#70453, the framework has a `DirectiveFixture` in addition to the `ComponentFixture`. These changes expand the APIs in the `TestbedHarnessEnvironment` to account for directive fixtures.
Adds
TestBed.createDirectiveto make testing directives easier.Fixes #54164.