test(ivy): more precise TestBed failure causes for View/Content Queries (FW-670) (#27447)
PR Close #27447
This commit is contained in:

committed by
Igor Minar

parent
295e0f65a1
commit
130ae158c4
@ -968,4 +968,82 @@ describe('ngtsc behavioral tests', () => {
|
||||
const jsContents = env.getContents('test.js');
|
||||
expect(jsContents).toMatch(/directives: \[DirA,\s+DirB\]/);
|
||||
});
|
||||
|
||||
describe('duplicate local refs', () => {
|
||||
const getComponentScript = (template: string): string => `
|
||||
import {Component, Directive, NgModule} from '@angular/core';
|
||||
|
||||
@Component({selector: 'my-cmp', template: \`${template}\`})
|
||||
class Cmp {}
|
||||
|
||||
@NgModule({declarations: [Cmp]})
|
||||
class Module {}
|
||||
`;
|
||||
|
||||
// Components with templates listed below should
|
||||
// throw the "ref is already defined" error
|
||||
const invalidCases = [
|
||||
`
|
||||
<div #ref></div>
|
||||
<div #ref></div>
|
||||
`,
|
||||
`
|
||||
<div #ref>
|
||||
<div #ref></div>
|
||||
</div>
|
||||
`,
|
||||
`
|
||||
<div>
|
||||
<div #ref></div>
|
||||
</div>
|
||||
<div>
|
||||
<div #ref></div>
|
||||
</div>
|
||||
`,
|
||||
`
|
||||
<ng-container>
|
||||
<div #ref></div>
|
||||
</ng-container>
|
||||
<div #ref></div>
|
||||
`
|
||||
];
|
||||
|
||||
// Components with templates listed below should not throw
|
||||
// the error, since refs are located in different scopes
|
||||
const validCases = [
|
||||
`
|
||||
<ng-template>
|
||||
<div #ref></div>
|
||||
</ng-template>
|
||||
<div #ref></div>
|
||||
`,
|
||||
`
|
||||
<div *ngIf="visible" #ref></div>
|
||||
<div #ref></div>
|
||||
`,
|
||||
`
|
||||
<div *ngFor="let item of items" #ref></div>
|
||||
<div #ref></div>
|
||||
`
|
||||
];
|
||||
|
||||
invalidCases.forEach(template => {
|
||||
it('should throw in case of duplicate refs', () => {
|
||||
env.tsconfig();
|
||||
env.write('test.ts', getComponentScript(template));
|
||||
const errors = env.driveDiagnostics();
|
||||
expect(errors[0].messageText)
|
||||
.toContain('Internal Error: The name ref is already defined in scope');
|
||||
});
|
||||
});
|
||||
|
||||
validCases.forEach(template => {
|
||||
it('should not throw in case refs are in different scopes', () => {
|
||||
env.tsconfig();
|
||||
env.write('test.ts', getComponentScript(template));
|
||||
const errors = env.driveDiagnostics();
|
||||
expect(errors.length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user