refactor(language-service): move to using mockHost as much as possible (#32589)
Update tests that still do not use `mockHost` for certain operations, like `addCode`. PR Close #32589
This commit is contained in:
parent
a32df388f8
commit
d30cd3309b
|
@ -48,7 +48,7 @@ describe('completions', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to infer the type of a ngForOf', () => {
|
it('should be able to infer the type of a ngForOf', () => {
|
||||||
addCode(
|
addCodeAndCallback(
|
||||||
`
|
`
|
||||||
interface Person {
|
interface Person {
|
||||||
name: string,
|
name: string,
|
||||||
|
@ -63,7 +63,7 @@ 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', () => {
|
||||||
addCode(
|
addCodeAndCallback(
|
||||||
`
|
`
|
||||||
interface Person {
|
interface Person {
|
||||||
name: string,
|
name: string,
|
||||||
|
@ -142,13 +142,13 @@ describe('completions', () => {
|
||||||
export class MyComponent {
|
export class MyComponent {
|
||||||
|
|
||||||
}`;
|
}`;
|
||||||
addCode(code, fileName => { contains(fileName, 'inside-template', 'h1'); });
|
addCodeAndCallback(code, fileName => { contains(fileName, 'inside-template', 'h1'); });
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should hot crash with an incomplete class', () => {
|
it('should hot crash with an incomplete class', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
addCode('\nexport class', fileName => { ngHost.getAnalyzedModules(); });
|
addCodeAndCallback('\nexport class', fileName => { ngHost.getAnalyzedModules(); });
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ export class MyComponent {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work with input and output', () => {
|
it('should work with input and output', () => {
|
||||||
addCode(
|
addCodeAndCallback(
|
||||||
`
|
`
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'foo-component',
|
selector: 'foo-component',
|
||||||
|
@ -202,14 +202,11 @@ export class MyComponent {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function addCode(code: string, cb: (fileName: string, content?: string) => void) {
|
function addCodeAndCallback(code: string, cb: (fileName: string, content?: string) => void) {
|
||||||
const fileName = '/app/app.component.ts';
|
const fileName = mockHost.addCode(code);
|
||||||
const originalContent = mockHost.getFileContent(fileName);
|
|
||||||
const newContent = originalContent + code;
|
|
||||||
mockHost.override(fileName, originalContent + code);
|
|
||||||
ngHost.getAnalyzedModules();
|
ngHost.getAnalyzedModules();
|
||||||
try {
|
try {
|
||||||
cb(fileName, newContent);
|
cb(fileName, mockHost.getFileContent(fileName) !);
|
||||||
} finally {
|
} finally {
|
||||||
mockHost.override(fileName, undefined !);
|
mockHost.override(fileName, undefined !);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import {MockTypescriptHost} from './test_utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note: If we want to test that a specific diagnostic message is emitted, then
|
* Note: If we want to test that a specific diagnostic message is emitted, then
|
||||||
* use the `addCode()` helper method to add code to an existing file and check
|
* use the `mockHost.addCode()` helper method to add code to an existing file and check
|
||||||
* that the diagnostic messages contain the expected output.
|
* that the diagnostic messages contain the expected output.
|
||||||
*
|
*
|
||||||
* If the goal is to assert that there is no error in a specific file, then use
|
* If the goal is to assert that there is no error in a specific file, then use
|
||||||
|
@ -90,7 +90,7 @@ describe('diagnostics', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not crash with a incomplete *ngFor', () => {
|
it('should not crash with a incomplete *ngFor', () => {
|
||||||
const fileName = addCode(`
|
const fileName = mockHost.addCode(`
|
||||||
@Component({
|
@Component({
|
||||||
template: '<div *ngFor></div> ~{after-div}'
|
template: '<div *ngFor></div> ~{after-div}'
|
||||||
})
|
})
|
||||||
|
@ -99,7 +99,7 @@ describe('diagnostics', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should report a component not in a module', () => {
|
it('should report a component not in a module', () => {
|
||||||
const fileName = addCode(`
|
const fileName = mockHost.addCode(`
|
||||||
@Component({
|
@Component({
|
||||||
template: '<div></div>'
|
template: '<div></div>'
|
||||||
})
|
})
|
||||||
|
@ -132,7 +132,7 @@ describe('diagnostics', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not throw getting diagnostics for an index expression', () => {
|
it('should not throw getting diagnostics for an index expression', () => {
|
||||||
const fileName = addCode(`
|
const fileName = mockHost.addCode(`
|
||||||
@Component({
|
@Component({
|
||||||
template: '<a *ngIf="(auth.isAdmin | async) || (event.leads && event.leads[(auth.uid | async)])"></a>'
|
template: '<a *ngIf="(auth.isAdmin | async) || (event.leads && event.leads[(auth.uid | async)])"></a>'
|
||||||
})
|
})
|
||||||
|
@ -141,7 +141,7 @@ describe('diagnostics', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not throw using a directive with no value', () => {
|
it('should not throw using a directive with no value', () => {
|
||||||
const fileName = addCode(`
|
const fileName = mockHost.addCode(`
|
||||||
@Component({
|
@Component({
|
||||||
template: '<form><input [(ngModel)]="name" required /></form>'
|
template: '<form><input [(ngModel)]="name" required /></form>'
|
||||||
})
|
})
|
||||||
|
@ -185,7 +185,7 @@ describe('diagnostics', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not throw for an invalid class', () => {
|
it('should not throw for an invalid class', () => {
|
||||||
const fileName = addCode(`
|
const fileName = mockHost.addCode(`
|
||||||
@Component({
|
@Component({
|
||||||
template: ''
|
template: ''
|
||||||
}) class`);
|
}) class`);
|
||||||
|
@ -501,12 +501,4 @@ describe('diagnostics', () => {
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function addCode(code: string) {
|
|
||||||
const fileName = '/app/app.component.ts';
|
|
||||||
const originalContent = mockHost.getFileContent(fileName);
|
|
||||||
const newContent = originalContent + code;
|
|
||||||
mockHost.override(fileName, newContent);
|
|
||||||
return fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue