From 00aad5904791b48d9f8ebd34af52d4995baf9554 Mon Sep 17 00:00:00 2001 From: Daniel Trevino <23410540+danieltre23@users.noreply.github.com> Date: Wed, 11 Aug 2021 23:55:56 +0000 Subject: [PATCH] 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 --- .../ivy/test/diagnostic_spec.ts | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/packages/language-service/ivy/test/diagnostic_spec.ts b/packages/language-service/ivy/test/diagnostic_spec.ts index 909558eb760..4bffd146778 100644 --- a/packages/language-service/ivy/test/diagnostic_spec.ts +++ b/packages/language-service/ivy/test/diagnostic_spec.ts @@ -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': `
` + }; + 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': `` + }; + const project = createModuleAndProjectWithDeclarations(env, 'test', files); + + const diags = project.getDiagnosticsForFile('app.html'); + expect(diags.length).toEqual(0); + }); }); function getTextOfDiagnostic(diag: ts.Diagnostic): string {