test(language-service): delete expression-cases.ts (#36468)
This commit deletes `expression-cases.ts` and moves the test cases to inline expressions in TEST_TEMPLATE. PR Close #36468
This commit is contained in:
parent
5fa7b8ba56
commit
e145fa13b1
|
@ -246,9 +246,9 @@ describe('diagnostics', () => {
|
||||||
expect(diags).toEqual([]);
|
expect(diags).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('in expression-cases.ts', () => {
|
|
||||||
it('should report access to an unknown field', () => {
|
it('should report access to an unknown field', () => {
|
||||||
const diags = ngLS.getSemanticDiagnostics(EXPRESSION_CASES).map(d => d.messageText);
|
mockHost.override(TEST_TEMPLATE, `{{ foo }}`);
|
||||||
|
const diags = ngLS.getSemanticDiagnostics(TEST_TEMPLATE).map(d => d.messageText);
|
||||||
expect(diags).toContain(
|
expect(diags).toContain(
|
||||||
`Identifier 'foo' is not defined. ` +
|
`Identifier 'foo' is not defined. ` +
|
||||||
`The component declaration, template variable declarations, ` +
|
`The component declaration, template variable declarations, ` +
|
||||||
|
@ -256,21 +256,23 @@ describe('diagnostics', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should report access to an unknown sub-field', () => {
|
it('should report access to an unknown sub-field', () => {
|
||||||
const diags = ngLS.getSemanticDiagnostics(EXPRESSION_CASES).map(d => d.messageText);
|
mockHost.override(TEST_TEMPLATE, `{{ hero.nam }}`);
|
||||||
|
const diags = ngLS.getSemanticDiagnostics(TEST_TEMPLATE).map(d => d.messageText);
|
||||||
expect(diags).toContain(
|
expect(diags).toContain(
|
||||||
`Identifier 'nam' is not defined. 'Person' does not contain such a member`);
|
`Identifier 'nam' is not defined. 'Hero' does not contain such a member`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should report access to a private member', () => {
|
it('should report access to a private member', () => {
|
||||||
const diags = ngLS.getSemanticDiagnostics(EXPRESSION_CASES).map(d => d.messageText);
|
mockHost.override(TEST_TEMPLATE, `{{ myField }}`);
|
||||||
|
const diags = ngLS.getSemanticDiagnostics(TEST_TEMPLATE).map(d => d.messageText);
|
||||||
expect(diags).toContain(`Identifier 'myField' refers to a private member of the component`);
|
expect(diags).toContain(`Identifier 'myField' refers to a private member of the component`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should report numeric operator errors', () => {
|
it('should report numeric operator errors', () => {
|
||||||
const diags = ngLS.getSemanticDiagnostics(EXPRESSION_CASES).map(d => d.messageText);
|
mockHost.override(TEST_TEMPLATE, `{{ 'a' % 2 }}`);
|
||||||
|
const diags = ngLS.getSemanticDiagnostics(TEST_TEMPLATE).map(d => d.messageText);
|
||||||
expect(diags).toContain('Expected a number type');
|
expect(diags).toContain('Expected a number type');
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('in ng-for-cases.ts', () => {
|
describe('in ng-for-cases.ts', () => {
|
||||||
it('should report an unknown field', () => {
|
it('should report an unknown field', () => {
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
/**
|
|
||||||
* @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 {Component} from '@angular/core';
|
|
||||||
|
|
||||||
export interface Person {
|
|
||||||
name: string;
|
|
||||||
age: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
template: '{{~{start-foo}foo~{end-foo}}}',
|
|
||||||
})
|
|
||||||
export class WrongFieldReference {
|
|
||||||
bar = 'bar';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
template: '{{~{start-nam}person.nam~{end-nam}}}',
|
|
||||||
})
|
|
||||||
export class WrongSubFieldReference {
|
|
||||||
person: Person = {name: 'Bob', age: 23};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
template: '{{~{start-myField}myField~{end-myField}}}',
|
|
||||||
})
|
|
||||||
export class PrivateReference {
|
|
||||||
private myField = 'My Field';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
template: '{{~{start-mod}"a" ~{end-mod}% 2}}',
|
|
||||||
})
|
|
||||||
export class ExpectNumericType {
|
|
||||||
}
|
|
|
@ -9,9 +9,7 @@
|
||||||
import {CommonModule} from '@angular/common';
|
import {CommonModule} from '@angular/common';
|
||||||
import {NgModule} from '@angular/core';
|
import {NgModule} from '@angular/core';
|
||||||
import {FormsModule} from '@angular/forms';
|
import {FormsModule} from '@angular/forms';
|
||||||
|
|
||||||
import {AppComponent} from './app.component';
|
import {AppComponent} from './app.component';
|
||||||
import * as ExpressionCases from './expression-cases';
|
|
||||||
import * as NgForCases from './ng-for-cases';
|
import * as NgForCases from './ng-for-cases';
|
||||||
import * as NgIfCases from './ng-if-cases';
|
import * as NgIfCases from './ng-if-cases';
|
||||||
import * as ParsingCases from './parsing-cases';
|
import * as ParsingCases from './parsing-cases';
|
||||||
|
@ -20,10 +18,6 @@ import * as ParsingCases from './parsing-cases';
|
||||||
imports: [CommonModule, FormsModule],
|
imports: [CommonModule, FormsModule],
|
||||||
declarations: [
|
declarations: [
|
||||||
AppComponent,
|
AppComponent,
|
||||||
ExpressionCases.ExpectNumericType,
|
|
||||||
ExpressionCases.PrivateReference,
|
|
||||||
ExpressionCases.WrongFieldReference,
|
|
||||||
ExpressionCases.WrongSubFieldReference,
|
|
||||||
NgForCases.UnknownEven,
|
NgForCases.UnknownEven,
|
||||||
NgForCases.UnknownPeople,
|
NgForCases.UnknownPeople,
|
||||||
NgForCases.UnknownTrackBy,
|
NgForCases.UnknownTrackBy,
|
||||||
|
|
|
@ -169,6 +169,7 @@ export class TemplateReference {
|
||||||
birthday = new Date();
|
birthday = new Date();
|
||||||
readonlyHeroes: ReadonlyArray<Readonly<Hero>> = this.heroes;
|
readonlyHeroes: ReadonlyArray<Readonly<Hero>> = this.heroes;
|
||||||
constNames = [{name: 'name'}] as const;
|
constNames = [{name: 'name'}] as const;
|
||||||
|
private myField = 'My Field';
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|
|
@ -57,8 +57,8 @@ describe('plugin', () => {
|
||||||
const compilerDiags = tsLS.getCompilerOptionsDiagnostics();
|
const compilerDiags = tsLS.getCompilerOptionsDiagnostics();
|
||||||
expect(compilerDiags).toEqual([]);
|
expect(compilerDiags).toEqual([]);
|
||||||
const sourceFiles = program.getSourceFiles().filter(f => !f.fileName.endsWith('.d.ts'));
|
const sourceFiles = program.getSourceFiles().filter(f => !f.fileName.endsWith('.d.ts'));
|
||||||
// there are six .ts files in the test project
|
// there are five .ts files in the test project
|
||||||
expect(sourceFiles.length).toBe(6);
|
expect(sourceFiles.length).toBe(5);
|
||||||
for (const {fileName} of sourceFiles) {
|
for (const {fileName} of sourceFiles) {
|
||||||
const syntacticDiags = tsLS.getSyntacticDiagnostics(fileName);
|
const syntacticDiags = tsLS.getSyntacticDiagnostics(fileName);
|
||||||
expect(syntacticDiags).toEqual([]);
|
expect(syntacticDiags).toEqual([]);
|
||||||
|
|
Loading…
Reference in New Issue