The method `getTemplateReferences()` appears in both the LanguageService interface and LanguageServiceHost interface. It should belong in the latter and not the former, since the former deals with the semantics of the language and not the mechanics. PR Close #33807
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
*
|
|
* 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';
|
|
|
|
import {TypeScriptServiceHost} from '../src/typescript_host';
|
|
|
|
import {MockTypescriptHost} from './test_utils';
|
|
|
|
describe('references', () => {
|
|
const mockHost = new MockTypescriptHost(['/app/main.ts']);
|
|
const service = ts.createLanguageService(mockHost);
|
|
const ngHost = new TypeScriptServiceHost(mockHost, service);
|
|
|
|
beforeEach(() => { mockHost.reset(); });
|
|
|
|
it('should be able to determine that test.ng is a template reference', () => {
|
|
const templates = ngHost.getTemplateReferences();
|
|
expect(templates).toEqual(['/app/test.ng']);
|
|
});
|
|
|
|
it('should be able to get template references for an invalid project', () => {
|
|
const moduleCode = `
|
|
import {NgModule} from '@angular/core';
|
|
import {NewClass} from './test.component';
|
|
|
|
@NgModule({declarations: [NewClass]}) export class TestModule {}`;
|
|
const classCode = `
|
|
export class NewClass {}
|
|
|
|
@Component({})
|
|
export class SomeComponent {}
|
|
`;
|
|
mockHost.addScript('/app/test.module.ts', moduleCode);
|
|
mockHost.addScript('/app/test.component.ts', classCode);
|
|
const templates = ngHost.getTemplateReferences();
|
|
expect(templates).toEqual(['/app/test.ng']);
|
|
});
|
|
|
|
});
|