-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: update acceptance core tests to work with es2015 (#44505)
Updates the acceptance core tests to work with ES2015 devmode output. There were two issues surfacing: * The NodeJS test execution failed because Domino does not handle destructuring syntax properly. This is because `Node.children` is not an iterable. * `forwardRef` does not work with ES2015 and TypeScript's decorator downlevel emit. This is a known limitation we work around in Angular applications by either compiling tests with the Angular compiler, or by running a custom decorator downlevel transform (like in the CLI). PR Close #44505
- Loading branch information
1 parent
cefe9f0
commit b734ceb
Showing
5 changed files
with
135 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Component, Directive, forwardRef, Host, Inject, ViewChild} from '@angular/core'; | ||
import {TestBed} from '@angular/core/testing'; | ||
|
||
// **NOTE**: More details on why tests relying on `forwardRef` are put into this | ||
// file can be found in the `BUILD.bazel` file declaring the forward ref test target. | ||
|
||
describe('di with forwardRef', () => { | ||
describe('directive injection', () => { | ||
it('should throw if directives try to inject each other', () => { | ||
@Directive({selector: '[dirB]'}) | ||
class DirectiveB { | ||
constructor(@Inject(forwardRef(() => DirectiveA)) siblingDir: DirectiveA) {} | ||
} | ||
|
||
@Directive({selector: '[dirA]'}) | ||
class DirectiveA { | ||
constructor(siblingDir: DirectiveB) {} | ||
} | ||
|
||
@Component({template: '<div dirA dirB></div>'}) | ||
class MyComp { | ||
} | ||
|
||
TestBed.configureTestingModule({declarations: [DirectiveA, DirectiveB, MyComp]}); | ||
expect(() => TestBed.createComponent(MyComp)) | ||
.toThrowError( | ||
'NG0200: Circular dependency in DI detected for DirectiveA. Find more at https://angular.io/errors/NG0200'); | ||
}); | ||
|
||
describe('flags', () => { | ||
describe('@Host', () => { | ||
it('should find host component on the host itself', () => { | ||
@Directive({selector: '[dirComp]'}) | ||
class DirectiveComp { | ||
constructor(@Inject(forwardRef(() => MyComp)) @Host() public comp: MyComp) {} | ||
} | ||
|
||
@Component({selector: 'my-comp', template: '<div dirComp></div>'}) | ||
class MyComp { | ||
@ViewChild(DirectiveComp) dirComp!: DirectiveComp; | ||
} | ||
|
||
@Component({template: '<my-comp></my-comp>', jit: true}) | ||
class MyApp { | ||
@ViewChild(MyComp) myComp!: MyComp; | ||
} | ||
|
||
TestBed.configureTestingModule({declarations: [DirectiveComp, MyComp, MyApp]}); | ||
const fixture = TestBed.createComponent(MyApp); | ||
fixture.detectChanges(); | ||
|
||
const myComp = fixture.componentInstance.myComp; | ||
const dirComp = myComp.dirComp; | ||
expect(dirComp.comp).toBe(myComp); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters