2016-11-22 12:10:23 -05:00
|
|
|
/**
|
|
|
|
* @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 {createLanguageService} from '../src/language_service';
|
2019-05-17 09:02:20 -04:00
|
|
|
import {LanguageService} from '../src/types';
|
2016-11-22 12:10:23 -05:00
|
|
|
import {TypeScriptServiceHost} from '../src/typescript_host';
|
|
|
|
|
|
|
|
import {MockTypescriptHost} from './test_utils';
|
|
|
|
|
|
|
|
describe('references', () => {
|
2019-10-16 15:00:41 -04:00
|
|
|
const mockHost = new MockTypescriptHost(['/app/main.ts']);
|
|
|
|
const service = ts.createLanguageService(mockHost);
|
|
|
|
const ngHost = new TypeScriptServiceHost(mockHost, service);
|
|
|
|
const ngService = createLanguageService(ngHost);
|
|
|
|
|
|
|
|
beforeEach(() => { mockHost.reset(); });
|
2016-11-22 12:10:23 -05:00
|
|
|
|
|
|
|
it('should be able to get template references',
|
|
|
|
() => { expect(() => ngService.getTemplateReferences()).not.toThrow(); });
|
|
|
|
|
|
|
|
it('should be able to determine that test.ng is a template reference',
|
|
|
|
() => { expect(ngService.getTemplateReferences()).toContain('/app/test.ng'); });
|
2016-12-06 20:11:09 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
expect(() => { ngService.getTemplateReferences(); }).not.toThrow();
|
|
|
|
});
|
|
|
|
|
2019-06-18 19:55:53 -04:00
|
|
|
});
|