From 708ae4c8ef52117cd216c76c3e0466807d474be8 Mon Sep 17 00:00:00 2001 From: Keen Yee Liau Date: Wed, 18 Sep 2019 14:11:21 -0700 Subject: [PATCH] fix(language-service): Fix failing tests after merge (#32758) https://github.com/angular/angular/pull/32653 and https://github.com/angular/angular/pull/32592 created a conflict in test that caused CI to turn red. This PR fixes the failing tests. PR Close #32758 --- .../language-service/test/diagnostics_spec.ts | 52 ++++++++----------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/packages/language-service/test/diagnostics_spec.ts b/packages/language-service/test/diagnostics_spec.ts index 347cf4b0d6..d7847c559f 100644 --- a/packages/language-service/test/diagnostics_spec.ts +++ b/packages/language-service/test/diagnostics_spec.ts @@ -509,49 +509,41 @@ describe('diagnostics', () => { }); it('should report diagnostic for missing template or templateUrl', () => { - const fileName = mockHost.addCode(` + const fileName = '/app/app.component.ts'; + const content = mockHost.override(fileName, ` + import {Component} from '@angular/core'; + @Component({ selector: 'app-example', }) - export class AppExample {} - - @NgModule({ - declarations: [AppExample], - }) - export class AppModule {}`); + export class AppComponent {}`); const diags = ngLS.getDiagnostics(fileName); - const missingTemplateError = diags.find( - d => d.messageText === `Component 'AppExample' must have a template or templateUrl`); - expect(missingTemplateError).toBeDefined(); - - const {start, length} = missingTemplateError !; - const content = mockHost.getFileContent(fileName) !; - expect(start).toBe(content.lastIndexOf('Component')); + expect(diags.length).toBe(1); + const {file, messageText, start, length} = diags[0]; + expect(file !.fileName).toBe(fileName); + expect(messageText).toBe(`Component 'AppComponent' must have a template or templateUrl`); + expect(start).toBe(content.indexOf(`@Component`) + 1); expect(length).toBe('Component'.length); }); it('should report diagnostic for both template and templateUrl', () => { - const fileName = mockHost.addCode(` + const fileName = '/app/app.component.ts'; + const content = mockHost.override(fileName, ` + import {Component} from '@angular/core'; + @Component({ selector: 'app-example', template: '
', - templateUrl: './example.html', + templateUrl: './test.ng', }) - export class AppExample {} - - @NgModule({ - declarations: [AppExample], - }) - export class AppModule {}`); + export class AppComponent {}`); const diags = ngLS.getDiagnostics(fileName); - const dupTemplateError = diags.find( - d => d.messageText === - `Component 'AppExample' must not have both template and templateUrl`); - expect(dupTemplateError).toBeDefined(); - - const {start, length} = dupTemplateError !; - const content = mockHost.getFileContent(fileName) !; - expect(start).toBe(content.lastIndexOf('Component')); + expect(diags.length).toBe(1); + const {file, messageText, start, length} = diags[0]; + expect(file !.fileName).toBe(fileName); + expect(messageText) + .toBe(`Component 'AppComponent' must not have both template and templateUrl`); + expect(start).toBe(content.indexOf(`@Component`) + 1); expect(length).toBe('Component'.length); });