mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
test(language-service): add extended diagnostics test (#43107)
Add a test in the langauge-service to make sure the extended template diagnostics are being correctly generated. Refs #42966 PR Close #43107
This commit is contained in:
committed by
Alex Rickabaugh
parent
4d42a3ab10
commit
c389052bab
@@ -361,6 +361,47 @@ describe('getSemanticDiagnostics', () => {
|
||||
expect(diag.category).toBe(ts.DiagnosticCategory.Error);
|
||||
expect(getTextOfDiagnostic(diag)).toBe(`'./missing.css'`);
|
||||
});
|
||||
|
||||
it('should produce invalid banana in box warning', () => {
|
||||
const files = {
|
||||
'app.ts': `
|
||||
import {Component} from '@angular/core';
|
||||
@Component({
|
||||
selector: 'test',
|
||||
template: '<div ([notARealThing])="bar"></div>',
|
||||
})
|
||||
export class TestCmp {
|
||||
bar: string = "text";
|
||||
}
|
||||
`
|
||||
};
|
||||
const project = createModuleAndProjectWithDeclarations(
|
||||
env, 'test', files, {strictTemplates: true, _extendedTemplateDiagnostics: true});
|
||||
|
||||
const diags = project.getDiagnosticsForFile('app.ts');
|
||||
expect(diags.length).toEqual(1);
|
||||
expect(diags[0].code).toEqual(ErrorCode.INVALID_BANANA_IN_BOX);
|
||||
expect(diags[0].category).toEqual(ts.DiagnosticCategory.Warning);
|
||||
});
|
||||
|
||||
it('should not produce invalid banana in box warning', () => {
|
||||
const files = {
|
||||
'app.ts': `
|
||||
import {Component} from '@angular/core';
|
||||
@Component({
|
||||
selector: 'test',
|
||||
template: '<div ([notARealThing])="bar"></div>',
|
||||
})
|
||||
export class TestCmp {
|
||||
bar: string = "text";
|
||||
}
|
||||
`
|
||||
};
|
||||
const project = createModuleAndProjectWithDeclarations(env, 'test', files);
|
||||
|
||||
const diags = project.getDiagnosticsForFile('app.ts');
|
||||
expect(diags.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
function getTextOfDiagnostic(diag: ts.Diagnostic): string {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {LegacyNgcOptions, StrictTemplateOptions} from '@angular/compiler-cli/src/ngtsc/core/api';
|
||||
import {InternalOptions, LegacyNgcOptions, StrictTemplateOptions} from '@angular/compiler-cli/src/ngtsc/core/api';
|
||||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, getSourceFileOrError} from '@angular/compiler-cli/src/ngtsc/file_system';
|
||||
import {OptimizeFor, TemplateTypeChecker} from '@angular/compiler-cli/src/ngtsc/typecheck/api';
|
||||
import * as ts from 'typescript/lib/tsserverlibrary';
|
||||
@@ -44,7 +44,8 @@ function writeTsconfig(
|
||||
null, 2));
|
||||
}
|
||||
|
||||
export type TestableOptions = StrictTemplateOptions&Pick<LegacyNgcOptions, 'fullTemplateTypeCheck'>;
|
||||
export type TestableOptions =
|
||||
StrictTemplateOptions&InternalOptions&Pick<LegacyNgcOptions, 'fullTemplateTypeCheck'>;
|
||||
|
||||
export class Project {
|
||||
private tsProject: ts.server.Project;
|
||||
|
||||
Reference in New Issue
Block a user