mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
test(language-service): add test for extended diagnostics (#43134)
Add a test to make sure extended template diagnostics are being correctly generated in the language service for non-ts files. Refs #42966 PR Close #43134
This commit is contained in:
committed by
Alex Rickabaugh
parent
b34a9a1eb2
commit
00aad59047
@@ -384,7 +384,7 @@ describe('getSemanticDiagnostics', () => {
|
||||
expect(diags[0].category).toEqual(ts.DiagnosticCategory.Warning);
|
||||
});
|
||||
|
||||
it('should not produce invalid banana in box warning', () => {
|
||||
it('should not produce invalid banana in box warning without the required flags', () => {
|
||||
const files = {
|
||||
'app.ts': `
|
||||
import {Component} from '@angular/core';
|
||||
@@ -402,6 +402,50 @@ describe('getSemanticDiagnostics', () => {
|
||||
const diags = project.getDiagnosticsForFile('app.ts');
|
||||
expect(diags.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('should produce invalid banana in box warning in external html file', () => {
|
||||
const files = {
|
||||
'app.ts': `
|
||||
import {Component} from '@angular/core';
|
||||
@Component({
|
||||
selector: 'test',
|
||||
templateUrl: './app.html',
|
||||
})
|
||||
export class TestCmp {
|
||||
bar: string = "text";
|
||||
}
|
||||
`,
|
||||
'app.html': `<div ([foo])="bar"></div>`
|
||||
};
|
||||
const project = createModuleAndProjectWithDeclarations(
|
||||
env, 'test', files, {strictTemplates: true, _extendedTemplateDiagnostics: true});
|
||||
|
||||
const diags = project.getDiagnosticsForFile('app.html');
|
||||
expect(diags.length).toEqual(1);
|
||||
expect(diags[0].code).toEqual(ngErrorCode(ErrorCode.INVALID_BANANA_IN_BOX));
|
||||
expect(diags[0].category).toEqual(ts.DiagnosticCategory.Warning);
|
||||
});
|
||||
|
||||
it('should not produce invalid banana in box warning in external html file without the required flags',
|
||||
() => {
|
||||
const files = {
|
||||
'app.ts': `
|
||||
import {Component} from '@angular/core';
|
||||
@Component({
|
||||
selector: 'test',
|
||||
templateUrl: './app.html',
|
||||
})
|
||||
export class TestCmp {
|
||||
bar: string = "text";
|
||||
}
|
||||
`,
|
||||
'app.html': `<div ([foo])="bar"></div>`
|
||||
};
|
||||
const project = createModuleAndProjectWithDeclarations(env, 'test', files);
|
||||
|
||||
const diags = project.getDiagnosticsForFile('app.html');
|
||||
expect(diags.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
function getTextOfDiagnostic(diag: ts.Diagnostic): string {
|
||||
|
||||
Reference in New Issue
Block a user