Skip to content

Commit

Permalink
test(language-service): add extended diagnostics test (#43107)
Browse files Browse the repository at this point in the history
Add a test in the langauge-service to make sure the extended template
diagnostics are being correctly generated.

Refs #42966

PR Close #43107
  • Loading branch information
danieltre23 authored and alxhub committed Aug 19, 2021
1 parent e6b2bed commit cb8e51f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
41 changes: 41 additions & 0 deletions packages/language-service/ivy/test/diagnostic_spec.ts
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions packages/language-service/ivy/testing/src/project.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit cb8e51f

Please sign in to comment.