2020-04-30 18:48:20 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2020-04-30 18:48:20 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as ts from 'typescript/lib/tsserverlibrary';
|
|
|
|
|
|
|
|
import {LanguageService} from '../language_service';
|
|
|
|
|
|
|
|
import {APP_COMPONENT, setup} from './mock_host';
|
|
|
|
|
|
|
|
describe('diagnostic', () => {
|
|
|
|
const {project, service, tsLS} = setup();
|
|
|
|
const ngLS = new LanguageService(project, tsLS);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
service.reset();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not produce error for AppComponent', () => {
|
|
|
|
const diags = ngLS.getSemanticDiagnostics(APP_COMPONENT);
|
|
|
|
expect(diags).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should report member does not exist', () => {
|
|
|
|
const content = service.overwriteInlineTemplate(APP_COMPONENT, '{{ nope }}');
|
|
|
|
const diags = ngLS.getSemanticDiagnostics(APP_COMPONENT);
|
|
|
|
expect(diags.length).toBe(1);
|
|
|
|
const {category, file, start, length, messageText} = diags[0];
|
|
|
|
expect(category).toBe(ts.DiagnosticCategory.Error);
|
|
|
|
expect(file?.fileName).toBe(APP_COMPONENT);
|
|
|
|
expect(content.substring(start!, start! + length!)).toBe('nope');
|
|
|
|
expect(messageText).toBe(`Property 'nope' does not exist on type 'AppComponent'.`);
|
|
|
|
});
|
|
|
|
});
|