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
This commit is contained in:
Keen Yee Liau 2019-09-18 14:11:21 -07:00 committed by Andrew Kushnir
parent 5c2e890d76
commit 708ae4c8ef
1 changed files with 22 additions and 30 deletions

View File

@ -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: '<div></div>',
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);
});