Skip to content

Commit 41667de

Browse files
JiaLiPassionkara
authored andcommitted
fix(zone.js): add issue numbers of @types/jasmine to the test cases (#34625)
Some cases will still need to use `spy as any` cast, because `@types/jasmine` have some issues, 1. The issue jasmine doesn't handle optional method properties, DefinitelyTyped/DefinitelyTyped#43486 2. The issue jasmine doesn't handle overload method correctly, DefinitelyTyped/DefinitelyTyped#42455 PR Close #34625
1 parent ef4736d commit 41667de

22 files changed

Lines changed: 5831 additions & 5583 deletions

File tree

packages/common/http/test/xhr_spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const XSSI_PREFIX = ')]}\'\n';
2929

3030
{
3131
describe('XhrBackend', () => {
32-
let factory: MockXhrFactory = null !;
33-
let backend: HttpXhrBackend = null !;
32+
let factory: MockXhrFactory = null!;
33+
let backend: HttpXhrBackend = null!;
3434
beforeEach(() => {
3535
factory = new MockXhrFactory();
3636
backend = new HttpXhrBackend(factory);
@@ -92,7 +92,7 @@ const XSSI_PREFIX = ')]}\'\n';
9292
factory.mock.mockFlush(200, 'OK', JSON.stringify({data: 'some data'}));
9393
expect(events.length).toBe(2);
9494
const res = events[1] as HttpResponse<{data: string}>;
95-
expect(res.body !.data).toBe('some data');
95+
expect(res.body!.data).toBe('some data');
9696
});
9797
it('handles a blank json response', () => {
9898
const events = trackEvents(backend.handle(TEST_POST.clone({responseType: 'json'})));
@@ -106,14 +106,14 @@ const XSSI_PREFIX = ')]}\'\n';
106106
factory.mock.mockFlush(500, 'Error', JSON.stringify({data: 'some data'}));
107107
expect(events.length).toBe(2);
108108
const res = events[1] as any as HttpErrorResponse;
109-
expect(res.error !.data).toBe('some data');
109+
expect(res.error!.data).toBe('some data');
110110
});
111111
it('handles a json error response with XSSI prefix', () => {
112112
const events = trackEvents(backend.handle(TEST_POST.clone({responseType: 'json'})));
113113
factory.mock.mockFlush(500, 'Error', XSSI_PREFIX + JSON.stringify({data: 'some data'}));
114114
expect(events.length).toBe(2);
115115
const res = events[1] as any as HttpErrorResponse;
116-
expect(res.error !.data).toBe('some data');
116+
expect(res.error!.data).toBe('some data');
117117
});
118118
it('handles a json string response', () => {
119119
const events = trackEvents(backend.handle(TEST_POST.clone({responseType: 'json'})));
@@ -128,7 +128,7 @@ const XSSI_PREFIX = ')]}\'\n';
128128
factory.mock.mockFlush(200, 'OK', XSSI_PREFIX + JSON.stringify({data: 'some data'}));
129129
expect(events.length).toBe(2);
130130
const res = events[1] as HttpResponse<{data: string}>;
131-
expect(res.body !.data).toBe('some data');
131+
expect(res.body!.data).toBe('some data');
132132
});
133133
it('emits unsuccessful responses via the error path', done => {
134134
backend.handle(TEST_POST).subscribe(undefined, (err: HttpErrorResponse) => {

packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ runInEachFileSystem(() => {
3838
initMockFileSystem(fs, testFiles);
3939

4040
// Force single-process execution in unit tests by mocking available CPUs to 1.
41-
spyOn(os, 'cpus').and.returnValue([{ model: 'Mock CPU' } as any]);
41+
spyOn(os, 'cpus').and.returnValue([{model: 'Mock CPU'} as any]);
4242
});
4343

4444
it('should run ngcc without errors for esm2015', () => {

packages/compiler-cli/ngcc/test/locking/lockfile_with_child_process/unlocker_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('unlocker', () => {
1313
spyOn(process, 'on');
1414
require('../../../src/locking/lock_file_with_child_process/unlocker');
1515
// TODO: @JiaLiPassion, need to wait for @types/jasmine to handle the override case
16+
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/42455
1617
expect(process.on).toHaveBeenCalledWith('disconnect' as any, jasmine.any(Function));
1718
});
1819
});

packages/compiler-cli/src/ngtsc/file_system/test/cached_file_system_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('CachedFileSystem', () => {
4747
let lstatSpy: jasmine.Spy;
4848
beforeEach(() => {
4949
// For most of the tests the files are not symbolic links.
50-
lstatSpy = spyOn(delegate, 'lstat').and.returnValue({ isSymbolicLink: () => false } as any);
50+
lstatSpy = spyOn(delegate, 'lstat').and.returnValue({isSymbolicLink: () => false} as any);
5151
});
5252

5353
it('should call delegate if not in cache', () => {
@@ -93,7 +93,7 @@ describe('CachedFileSystem', () => {
9393
describe('invalidateCaches()', () => {
9494
it('should call the delegate `readFile()` if the path for the cached file has been invalidated',
9595
() => {
96-
spyOn(delegate, 'lstat').and.returnValue({ isSymbolicLink: () => false } as any);
96+
spyOn(delegate, 'lstat').and.returnValue({isSymbolicLink: () => false} as any);
9797
const spy = spyOn(delegate, 'readFile').and.returnValue('Some contents');
9898
fs.readFile(abcPath); // Call once to fill the cache
9999
spy.calls.reset();
@@ -230,7 +230,7 @@ describe('CachedFileSystem', () => {
230230
describe('moveFile()', () => {
231231
beforeEach(() => {
232232
// `moveFile()` relies upon `readFile` which calls through to `lstat()`, so stub it out.
233-
spyOn(delegate, 'lstat').and.returnValue({ isSymbolicLink: () => false } as any);
233+
spyOn(delegate, 'lstat').and.returnValue({isSymbolicLink: () => false} as any);
234234
});
235235

236236
it('should call delegate', () => {

packages/compiler-cli/src/ngtsc/file_system/test/node_js_file_system_spec.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ describe('NodeJSFileSystem', () => {
6969
const result = fs.readdir(abcPath);
7070
expect(result).toEqual([relativeFrom('x'), relativeFrom('y/z')]);
7171
// TODO: @JiaLiPassion need to wait for @types/jasmine update to handle optional parameters.
72+
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486
7273
expect(spy as any).toHaveBeenCalledWith(abcPath);
7374
});
7475
});
@@ -90,6 +91,7 @@ describe('NodeJSFileSystem', () => {
9091
const result = fs.stat(abcPath);
9192
expect(result).toBe(stats);
9293
// TODO: @JiaLiPassion need to wait for @types/jasmine update to handle optional parameters.
94+
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486
9395
expect(spy as any).toHaveBeenCalledWith(abcPath);
9496
});
9597
});
@@ -173,12 +175,14 @@ describe('NodeJSFileSystem', () => {
173175
}
174176
return false;
175177
});
176-
spyOn(fs, 'stat').and.returnValue({ isDirectory: () => true } as any);
177-
const mkdirSyncSpy = spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => {
178-
if (path === abcPath) {
179-
throw new Error('It exists already. Supposedly.');
180-
}
181-
}) as any);
178+
spyOn(fs, 'stat').and.returnValue({isDirectory: () => true} as any);
179+
const mkdirSyncSpy =
180+
spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => {
181+
if (path === abcPath) {
182+
throw new Error(
183+
'It exists already. Supposedly.');
184+
}
185+
}) as any);
182186

183187
fs.ensureDir(abcPath);
184188
expect(mkdirSyncSpy).toHaveBeenCalledTimes(3);
@@ -188,11 +192,12 @@ describe('NodeJSFileSystem', () => {
188192

189193
it('should fail if creating the directory throws and the directory does not exist', () => {
190194
spyOn(fs, 'exists').and.returnValue(false);
191-
spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => {
192-
if (path === abcPath) {
193-
throw new Error('Unable to create directory (for whatever reason).');
194-
}
195-
}) as any);
195+
spyOn(realFs, 'mkdirSync')
196+
.and.callFake(((path: string) => {
197+
if (path === abcPath) {
198+
throw new Error('Unable to create directory (for whatever reason).');
199+
}
200+
}) as any);
196201

197202
expect(() => fs.ensureDir(abcPath))
198203
.toThrowError('Unable to create directory (for whatever reason).');
@@ -212,12 +217,12 @@ describe('NodeJSFileSystem', () => {
212217
}
213218
return false;
214219
});
215-
spyOn(fs, 'stat').and.returnValue({ isDirectory: isDirectorySpy } as any);
220+
spyOn(fs, 'stat').and.returnValue({isDirectory: isDirectorySpy} as any);
216221
spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => {
217-
if (path === abcPath) {
218-
throw new Error('It exists already. Supposedly.');
219-
}
220-
}) as any);
222+
if (path === abcPath) {
223+
throw new Error('It exists already. Supposedly.');
224+
}
225+
}) as any);
221226

222227
expect(() => fs.ensureDir(abcPath)).toThrowError('It exists already. Supposedly.');
223228
expect(isDirectorySpy).toHaveBeenCalledTimes(1);

packages/compiler-cli/test/ngc_spec.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ describe('ngc transformer command-line', () => {
4141
basePath = support.basePath;
4242
outDir = path.join(basePath, 'built');
4343
process.chdir(basePath);
44-
write = (fileName: string, content: string) => { support.write(fileName, content); };
44+
write = (fileName: string, content: string) => {
45+
support.write(fileName, content);
46+
};
4547

4648
write('tsconfig-base.json', `{
4749
"compilerOptions": {
@@ -96,8 +98,9 @@ describe('ngc transformer command-line', () => {
9698
});
9799

98100
describe('errors', () => {
99-
100-
beforeEach(() => { errorSpy.and.stub(); });
101+
beforeEach(() => {
102+
errorSpy.and.stub();
103+
});
101104

102105
it('should not print the stack trace if user input file does not exist', () => {
103106
writeConfig(`{
@@ -231,7 +234,6 @@ describe('ngc transformer command-line', () => {
231234
});
232235

233236
describe('compile ngfactory files', () => {
234-
235237
it('should compile ngfactory files that are not referenced by root files', () => {
236238
writeConfig(`{
237239
"extends": "./tsconfig-base.json",
@@ -1122,7 +1124,6 @@ describe('ngc transformer command-line', () => {
11221124
});
11231125

11241126
describe('with external symbol re-exports enabled', () => {
1125-
11261127
it('should be able to compile multiple libraries with summaries', () => {
11271128
// Note: we need to emit the generated code for the libraries
11281129
// into the node_modules, as that is the only way that we
@@ -1560,11 +1561,13 @@ describe('ngc transformer command-line', () => {
15601561
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
15611562
const timerToken = 100;
15621563
// TODO: @JiaLiPassion, need to wait @types/jasmine to handle optional method case
1564+
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486
15631565
spyOn(ts.sys as any, 'setTimeout').and.callFake((callback: () => void) => {
15641566
timer = callback;
15651567
return timerToken;
15661568
});
15671569
// TODO: @JiaLiPassion, need to wait @types/jasmine to handle optional method case
1570+
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486
15681571
spyOn(ts.sys as any, 'clearTimeout').and.callFake((token: number) => {
15691572
if (token == timerToken) {
15701573
timer = undefined;
@@ -1617,7 +1620,9 @@ describe('ngc transformer command-line', () => {
16171620
`);
16181621
});
16191622

1620-
afterEach(() => { jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; });
1623+
afterEach(() => {
1624+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
1625+
});
16211626

16221627
function writeAppConfig(location: string) {
16231628
writeConfig(`{
@@ -1672,11 +1677,13 @@ describe('ngc transformer command-line', () => {
16721677
`);
16731678
}));
16741679

1675-
it('should recompile when the html file changes',
1676-
expectRecompile(() => { write('greet.html', '<p> Hello {{name}} again!</p>'); }));
1680+
it('should recompile when the html file changes', expectRecompile(() => {
1681+
write('greet.html', '<p> Hello {{name}} again!</p>');
1682+
}));
16771683

1678-
it('should recompile when the css file changes',
1679-
expectRecompile(() => { write('greet.css', `p.greeting { color: blue }`); }));
1684+
it('should recompile when the css file changes', expectRecompile(() => {
1685+
write('greet.css', `p.greeting { color: blue }`);
1686+
}));
16801687
});
16811688

16821689
describe('regressions', () => {
@@ -2041,8 +2048,8 @@ describe('ngc transformer command-line', () => {
20412048
expect(exitCode).toBe(1, 'Compile was expected to fail');
20422049
const srcPathWithSep = `lib/`;
20432050
expect(messages[0])
2044-
.toEqual(
2045-
`${srcPathWithSep}test.component.ts(6,21): Error during template compile of 'TestComponent'
2051+
.toEqual(`${
2052+
srcPathWithSep}test.component.ts(6,21): Error during template compile of 'TestComponent'
20462053
Tagged template expressions are not supported in metadata in 't1'
20472054
't1' references 't2' at ${srcPathWithSep}indirect1.ts(3,27)
20482055
't2' contains the error at ${srcPathWithSep}indirect2.ts(4,27).
@@ -2051,7 +2058,6 @@ describe('ngc transformer command-line', () => {
20512058
});
20522059

20532060
describe('tree shakeable services', () => {
2054-
20552061
function compileService(source: string): string {
20562062
write('service.ts', source);
20572063

packages/compiler/test/output/value_util_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ describe('convertValueToOutputAst', () => {
1313
it('should convert all array elements, including undefined', () => {
1414
const ctx = null;
1515
const value = new Array(3).concat('foo');
16-
const expr = convertValueToOutputAst(ctx !, value) as o.LiteralArrayExpr;
17-
expect(expr instanceof o.LiteralArrayExpr);
16+
const expr = convertValueToOutputAst(ctx!, value) as o.LiteralArrayExpr;
17+
expect(expr instanceof o.LiteralArrayExpr).toBe(true);
1818
expect(expr.entries.length).toBe(4);
1919
for (let i = 0; i < 4; ++i) {
2020
expect(expr.entries[i] instanceof o.Expression).toBe(true);

0 commit comments

Comments
 (0)