test(language-service): Remove test cases from parsing-cases.ts (#34716)

This commit removes some test scenarios from `parsing-cases.ts` and
colocate them with the test code instead. This makes the tests easier to
read and understand.

PR Close #34716
This commit is contained in:
Keen Yee Liau 2020-01-09 18:31:43 -08:00 committed by atscott
parent f6dee72a88
commit 6d28a209e4
4 changed files with 13 additions and 47 deletions

View File

@ -372,9 +372,10 @@ describe('completions', () => {
describe('data binding', () => { describe('data binding', () => {
it('should be able to complete property value', () => { it('should be able to complete property value', () => {
const marker = mockHost.getLocationMarkerFor(PARSING_CASES, 'property-binding-model'); mockHost.override(TEST_TEMPLATE, `<h1 [model]="~{cursor}"></h1>`);
const completions = ngLS.getCompletionsAt(PARSING_CASES, marker.start); const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
expectContain(completions, CompletionKind.PROPERTY, ['test']); const completions = ngLS.getCompletionsAt(TEST_TEMPLATE, marker.start);
expectContain(completions, CompletionKind.PROPERTY, ['title']);
}); });
it('should be able to complete property read', () => { it('should be able to complete property read', () => {
@ -385,9 +386,10 @@ describe('completions', () => {
}); });
it('should be able to complete an event', () => { it('should be able to complete an event', () => {
const marker = mockHost.getLocationMarkerFor(PARSING_CASES, 'event-binding-model'); mockHost.override(TEST_TEMPLATE, `<h1 (model)="~{cursor}"></h1>`);
const completions = ngLS.getCompletionsAt(PARSING_CASES, marker.start); const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
expectContain(completions, CompletionKind.METHOD, ['modelChanged']); const completions = ngLS.getCompletionsAt(TEST_TEMPLATE, marker.start);
expectContain(completions, CompletionKind.METHOD, ['myClick']);
}); });
it('should be able to complete a the LHS of a two-way binding', () => { it('should be able to complete a the LHS of a two-way binding', () => {
@ -398,9 +400,10 @@ describe('completions', () => {
}); });
it('should be able to complete a the RHS of a two-way binding', () => { it('should be able to complete a the RHS of a two-way binding', () => {
const marker = mockHost.getLocationMarkerFor(PARSING_CASES, 'two-way-binding-model'); mockHost.override(TEST_TEMPLATE, `<h1 [(model)]="~{cursor}"></h1>`);
const completions = ngLS.getCompletionsAt(PARSING_CASES, marker.start); const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
expectContain(completions, CompletionKind.PROPERTY, ['test']); const completions = ngLS.getCompletionsAt(TEST_TEMPLATE, marker.start);
expectContain(completions, CompletionKind.PROPERTY, ['title']);
}); });
it('should suggest property binding for input', () => { it('should suggest property binding for input', () => {

View File

@ -30,21 +30,17 @@ import * as ParsingCases from './parsing-cases';
NgForCases.UnknownTrackBy, NgForCases.UnknownTrackBy,
NgIfCases.ShowIf, NgIfCases.ShowIf,
ParsingCases.AsyncForUsingComponent, ParsingCases.AsyncForUsingComponent,
ParsingCases.AttributeBinding,
ParsingCases.CaseIncompleteOpen, ParsingCases.CaseIncompleteOpen,
ParsingCases.CaseMissingClosing, ParsingCases.CaseMissingClosing,
ParsingCases.CaseUnknown, ParsingCases.CaseUnknown,
ParsingCases.EmptyInterpolation, ParsingCases.EmptyInterpolation,
ParsingCases.EventBinding,
ParsingCases.NoValueAttribute, ParsingCases.NoValueAttribute,
ParsingCases.NumberModel, ParsingCases.NumberModel,
ParsingCases.Pipes, ParsingCases.Pipes,
ParsingCases.PropertyBinding,
ParsingCases.References, ParsingCases.References,
ParsingCases.StringModel, ParsingCases.StringModel,
ParsingCases.TemplateReference, ParsingCases.TemplateReference,
ParsingCases.TestComponent, ParsingCases.TestComponent,
ParsingCases.TwoWayBinding,
] ]
}) })
export class AppModule { export class AppModule {

View File

@ -44,39 +44,6 @@ export class Pipes {
export class NoValueAttribute { export class NoValueAttribute {
} }
@Component({
template: '<h1 model="~{attribute-binding-model}test"></h1>',
})
export class AttributeBinding {
test: string = 'test';
}
@Component({
template: '<h1 [model]="~{property-binding-model}test"></h1>',
})
export class PropertyBinding {
test: string = 'test';
}
@Component({
template: '<h1 (model)="~{event-binding-model}modelChanged()"></h1>',
})
export class EventBinding {
test: string = 'test';
modelChanged() {}
}
@Component({
template: `
<h1 [(model)]="~{two-way-binding-model}test"></h1>
<input ~{two-way-binding-input}></input>`,
})
export class TwoWayBinding {
test: string = 'test';
}
@Directive({ @Directive({
selector: '[string-model]', selector: '[string-model]',
}) })

View File

@ -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(13); expect(templates.length).toBe(9);
}); });
it('should be able to find external template', () => { it('should be able to find external template', () => {