test(language-service): Inline test cases in parsing-cases.ts (#36495)
This commit removes individual components from parsing-cases.ts and colocate them with the actual tests. This makes the tests more readable. PR Close #36495
This commit is contained in:
parent
41667de778
commit
e485236502
|
@ -168,9 +168,10 @@ describe('completions', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to get completions in an empty interpolation', () => {
|
it('should be able to get completions in an empty interpolation', () => {
|
||||||
const marker = mockHost.getLocationMarkerFor(PARSING_CASES, 'empty-interpolation');
|
mockHost.override(TEST_TEMPLATE, `{{ ~{cursor} }}`);
|
||||||
const completions = ngLS.getCompletionsAtPosition(PARSING_CASES, marker.start);
|
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
|
||||||
expectContain(completions, CompletionKind.PROPERTY, ['title', 'subTitle']);
|
const completions = ngLS.getCompletionsAtPosition(TEST_TEMPLATE, marker.start);
|
||||||
|
expectContain(completions, CompletionKind.PROPERTY, ['title', 'hero']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should suggest $any() type cast function in an interpolation', () => {
|
it('should suggest $any() type cast function in an interpolation', () => {
|
||||||
|
@ -282,9 +283,14 @@ describe('completions', () => {
|
||||||
|
|
||||||
describe('with a *ngIf', () => {
|
describe('with a *ngIf', () => {
|
||||||
it('should be able to get completions for exported *ngIf variable', () => {
|
it('should be able to get completions for exported *ngIf variable', () => {
|
||||||
const marker = mockHost.getLocationMarkerFor(PARSING_CASES, 'promised-person-name');
|
mockHost.override(TEST_TEMPLATE, `
|
||||||
const completions = ngLS.getCompletionsAtPosition(PARSING_CASES, marker.start);
|
<div *ngIf="heroP | async as h">
|
||||||
expectContain(completions, CompletionKind.PROPERTY, ['name', 'age', 'street']);
|
{{ h.~{cursor} }}
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
|
||||||
|
const completions = ngLS.getCompletionsAtPosition(TEST_TEMPLATE, marker.start);
|
||||||
|
expectContain(completions, CompletionKind.PROPERTY, ['id', 'name']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -368,9 +374,14 @@ describe('completions', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to infer the type of a ngForOf with an async pipe', () => {
|
it('should be able to infer the type of a ngForOf with an async pipe', () => {
|
||||||
const marker = mockHost.getLocationMarkerFor(PARSING_CASES, 'async-person-name');
|
mockHost.override(TEST_TEMPLATE, `
|
||||||
const completions = ngLS.getCompletionsAtPosition(PARSING_CASES, marker.start);
|
<div *ngFor="let h of heroesP | async">
|
||||||
expectContain(completions, CompletionKind.PROPERTY, ['name', 'age', 'street']);
|
{{ h.~{cursor} }}
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
|
||||||
|
const completions = ngLS.getCompletionsAtPosition(TEST_TEMPLATE, marker.start);
|
||||||
|
expectContain(completions, CompletionKind.PROPERTY, ['id', 'name']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to resolve variable in nested loop', () => {
|
it('should be able to resolve variable in nested loop', () => {
|
||||||
|
@ -498,14 +509,27 @@ describe('completions', () => {
|
||||||
|
|
||||||
describe('with references', () => {
|
describe('with references', () => {
|
||||||
it('should list references', () => {
|
it('should list references', () => {
|
||||||
const marker = mockHost.getLocationMarkerFor(PARSING_CASES, 'test-comp-content');
|
mockHost.override(TEST_TEMPLATE, `
|
||||||
const completions = ngLS.getCompletionsAtPosition(PARSING_CASES, marker.start);
|
<div #myDiv>
|
||||||
expectContain(completions, CompletionKind.REFERENCE, ['div', 'test1', 'test2']);
|
<test-comp #test1>
|
||||||
|
{{ ~{cursor} }}
|
||||||
|
</test-comp>
|
||||||
|
</div>
|
||||||
|
<test-comp #test2></test-comp>
|
||||||
|
`);
|
||||||
|
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
|
||||||
|
const completions = ngLS.getCompletionsAtPosition(TEST_TEMPLATE, marker.start);
|
||||||
|
expectContain(completions, CompletionKind.REFERENCE, ['myDiv', 'test1', 'test2']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reference the component', () => {
|
it('should reference the component', () => {
|
||||||
const marker = mockHost.getLocationMarkerFor(PARSING_CASES, 'test-comp-after-test');
|
mockHost.override(TEST_TEMPLATE, `
|
||||||
const completions = ngLS.getCompletionsAtPosition(PARSING_CASES, marker.start);
|
<test-comp #test1>
|
||||||
|
{{ test1.~{cursor} }}
|
||||||
|
</test-comp>
|
||||||
|
`);
|
||||||
|
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
|
||||||
|
const completions = ngLS.getCompletionsAtPosition(TEST_TEMPLATE, marker.start);
|
||||||
expectContain(completions, CompletionKind.PROPERTY, ['name', 'testEvent']);
|
expectContain(completions, CompletionKind.PROPERTY, ['name', 'testEvent']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -342,7 +342,7 @@ describe('diagnostics', () => {
|
||||||
expect(category).toBe(ts.DiagnosticCategory.Error);
|
expect(category).toBe(ts.DiagnosticCategory.Error);
|
||||||
expect(messageText)
|
expect(messageText)
|
||||||
.toBe(
|
.toBe(
|
||||||
`Identifier 'missingField' is not defined. '{ implicitPerson: Person; }' does not contain such a member`,
|
`Identifier 'missingField' is not defined. '{ implicitPerson: Hero; }' does not contain such a member`,
|
||||||
);
|
);
|
||||||
const span = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'emb');
|
const span = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'emb');
|
||||||
expect(start).toBe(span.start);
|
expect(start).toBe(span.start);
|
||||||
|
@ -361,7 +361,7 @@ describe('diagnostics', () => {
|
||||||
expect(category).toBe(ts.DiagnosticCategory.Error);
|
expect(category).toBe(ts.DiagnosticCategory.Error);
|
||||||
expect(messageText)
|
expect(messageText)
|
||||||
.toBe(
|
.toBe(
|
||||||
`Identifier 'missingField' is not defined. 'Person' does not contain such a member`,
|
`Identifier 'missingField' is not defined. 'Hero' does not contain such a member`,
|
||||||
);
|
);
|
||||||
const span = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'emb');
|
const span = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'emb');
|
||||||
expect(start).toBe(span.start);
|
expect(start).toBe(span.start);
|
||||||
|
|
|
@ -16,16 +16,13 @@ import * as ParsingCases from './parsing-cases';
|
||||||
imports: [CommonModule, FormsModule],
|
imports: [CommonModule, FormsModule],
|
||||||
declarations: [
|
declarations: [
|
||||||
AppComponent,
|
AppComponent,
|
||||||
ParsingCases.AsyncForUsingComponent,
|
|
||||||
ParsingCases.CaseIncompleteOpen,
|
ParsingCases.CaseIncompleteOpen,
|
||||||
ParsingCases.CaseMissingClosing,
|
ParsingCases.CaseMissingClosing,
|
||||||
ParsingCases.CaseUnknown,
|
ParsingCases.CaseUnknown,
|
||||||
ParsingCases.CounterDirective,
|
ParsingCases.CounterDirective,
|
||||||
ParsingCases.EmptyInterpolation,
|
|
||||||
ParsingCases.HintModel,
|
ParsingCases.HintModel,
|
||||||
ParsingCases.NoValueAttribute,
|
ParsingCases.NoValueAttribute,
|
||||||
ParsingCases.NumberModel,
|
ParsingCases.NumberModel,
|
||||||
ParsingCases.References,
|
|
||||||
ParsingCases.StringModel,
|
ParsingCases.StringModel,
|
||||||
ParsingCases.TemplateReference,
|
ParsingCases.TemplateReference,
|
||||||
ParsingCases.TestComponent,
|
ParsingCases.TestComponent,
|
||||||
|
|
|
@ -63,45 +63,6 @@ export class HintModel {
|
||||||
hintChange: EventEmitter<string> = new EventEmitter();
|
hintChange: EventEmitter<string> = new EventEmitter();
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Person {
|
|
||||||
name: string;
|
|
||||||
age: number;
|
|
||||||
street: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
template: `
|
|
||||||
<div *ngFor="let person of people | async">
|
|
||||||
{{person.~{async-person-name}name}}
|
|
||||||
</div>
|
|
||||||
<div *ngIf="promisedPerson | async as person">
|
|
||||||
{{person.~{promised-person-name}name}}
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
})
|
|
||||||
export class AsyncForUsingComponent {
|
|
||||||
people: Promise<Person[]> = Promise.resolve([]);
|
|
||||||
promisedPerson: Promise<Person> = Promise.resolve({
|
|
||||||
name: 'John Doe',
|
|
||||||
age: 42,
|
|
||||||
street: '123 Angular Ln',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
template: `
|
|
||||||
<div #div>
|
|
||||||
<test-comp #test1>
|
|
||||||
{{~{test-comp-content}}}
|
|
||||||
{{test1.~{test-comp-after-test}name}}
|
|
||||||
{{div.~{test-comp-after-div}.innerText}}
|
|
||||||
</test-comp>
|
|
||||||
</div>
|
|
||||||
<test-comp #test2></test-comp>`,
|
|
||||||
})
|
|
||||||
export class References {
|
|
||||||
}
|
|
||||||
|
|
||||||
class CounterDirectiveContext<T> {
|
class CounterDirectiveContext<T> {
|
||||||
constructor(public $implicit: T) {}
|
constructor(public $implicit: T) {}
|
||||||
}
|
}
|
||||||
|
@ -121,8 +82,8 @@ export class CounterDirective implements OnChanges {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface WithContextDirectiveContext {
|
interface WithContextDirectiveContext {
|
||||||
$implicit: {implicitPerson: Person;};
|
$implicit: {implicitPerson: Hero;};
|
||||||
nonImplicitPerson: Person;
|
nonImplicitPerson: Hero;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive({selector: '[withContext]'})
|
@Directive({selector: '[withContext]'})
|
||||||
|
@ -156,7 +117,9 @@ export class TemplateReference {
|
||||||
*/
|
*/
|
||||||
title = 'Some title';
|
title = 'Some title';
|
||||||
hero: Hero = {id: 1, name: 'Windstorm'};
|
hero: Hero = {id: 1, name: 'Windstorm'};
|
||||||
|
heroP = Promise.resolve(this.hero);
|
||||||
heroes: Hero[] = [this.hero];
|
heroes: Hero[] = [this.hero];
|
||||||
|
heroesP = Promise.resolve(this.heroes);
|
||||||
tupleArray: [string, Hero] = ['test', this.hero];
|
tupleArray: [string, Hero] = ['test', this.hero];
|
||||||
league: Hero[][] = [this.heroes];
|
league: Hero[][] = [this.heroes];
|
||||||
heroesByName: {[name: string]: Hero} = {};
|
heroesByName: {[name: string]: Hero} = {};
|
||||||
|
@ -171,11 +134,3 @@ export class TemplateReference {
|
||||||
constNames = [{name: 'name'}] as const;
|
constNames = [{name: 'name'}] as const;
|
||||||
private myField = 'My Field';
|
private myField = 'My Field';
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
|
||||||
template: '{{~{empty-interpolation}}}',
|
|
||||||
})
|
|
||||||
export class EmptyInterpolation {
|
|
||||||
title = 'Some title';
|
|
||||||
subTitle = 'Some sub title';
|
|
||||||
}
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ describe('TypeScriptServiceHost', () => {
|
||||||
const tsLS = ts.createLanguageService(tsLSHost);
|
const tsLS = ts.createLanguageService(tsLSHost);
|
||||||
const ngLSHost = new TypeScriptServiceHost(tsLSHost, tsLS);
|
const ngLSHost = new TypeScriptServiceHost(tsLSHost, tsLS);
|
||||||
const templates = ngLSHost.getTemplates('/app/parsing-cases.ts');
|
const templates = ngLSHost.getTemplates('/app/parsing-cases.ts');
|
||||||
expect(templates.length).toBe(8);
|
expect(templates.length).toBe(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to find external template', () => {
|
it('should be able to find external template', () => {
|
||||||
|
|
Loading…
Reference in New Issue