+ {{user.does_not_exist}} +
\`, + }) + export class TestCmp { + user: {name: string}[]; + }`); - @Component({ - selector: 'test', - templateUrl: './template.html', - }) - export class TestCmp { - user: {name: string}[]; - } + const diags = env.driveDiagnostics(); + expect(diags.length).toBe(1); + expect(diags[0].file !.fileName).toBe(_('/test.ts')); + expect(getSourceCodeForDiagnostic(diags[0])).toBe('user.does_not_exist'); + }); - @NgModule({ - declarations: [TestCmp], - }) - export class Module {} - `); - env.write('template.html', `+ {{user.does_not_exist}} +
\`; - const diags = env.driveDiagnostics(); - expect(diags.length).toBe(1); - expect(diags[0].messageText).toContain('does_not_exist'); - expect(formatSpan(diags[0])).toEqual('/template.html: 1:14, 1:33'); + @Component({ + selector: 'test', + template: TEMPLATE, + }) + export class TestCmp { + user: {name: string}[]; + }`); + + const diags = env.driveDiagnostics(); + expect(diags.length).toBe(1); + expect(diags[0].file !.fileName).toBe(_('/test.ts') + ' (TestCmp template)'); + expect(getSourceCodeForDiagnostic(diags[0])).toBe('user.does_not_exist'); + expect(getSourceCodeForDiagnostic(diags[0].relatedInformation ![0])).toBe('TEMPLATE'); + }); + + it('should be correct for external templates', () => { + env.write('template.html', `+ {{user.does_not_exist}} +
`); + env.write('test.ts', ` + import {Component, NgModule} from '@angular/core'; + + + @Component({ + selector: 'test', + templateUrl: './template.html', + }) + export class TestCmp { + user: {name: string}[]; + }`); + + const diags = env.driveDiagnostics(); + expect(diags.length).toBe(1); + expect(diags[0].file !.fileName).toBe(_('/template.html')); + expect(getSourceCodeForDiagnostic(diags[0])).toBe('user.does_not_exist'); + expect(getSourceCodeForDiagnostic(diags[0].relatedInformation ![0])) + .toBe(`'./template.html'`); + }); }); }); }); -function formatSpan(diagnostic: ts.Diagnostic | Diagnostic): string { - if (diagnostic.source !== 'angular') { - return '