angular/packages/zone.js/test/node/http.spec.ts
Joey Perrott 9dbe6fc18b refactor: update license text to point to angular.dev (#57901)
Update license text to point to angular.dev instead of angular.io

PR Close #57901
2024-09-24 15:33:00 +02:00

44 lines
1.2 KiB
TypeScript

/**
* @license
* Copyright Google LLC 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.dev/license
*/
import http from 'http';
describe('http test', () => {
it('http.request should be patched as eventTask', (done) => {
const server = http.createServer((req: any, res: any) => {
res.end();
});
server.listen(9999, () => {
const zoneASpec = {
name: 'A',
onScheduleTask: (
delegate: ZoneDelegate,
currentZone: Zone,
targetZone: Zone,
task: Task,
): Task => {
return delegate.scheduleTask(targetZone, task);
},
};
const zoneA = Zone.current.fork(zoneASpec);
spyOn(zoneASpec, 'onScheduleTask').and.callThrough();
zoneA.run(() => {
const req = http.request(
{hostname: 'localhost', port: '9999', method: 'GET'},
(res: any) => {
expect(Zone.current.name).toEqual('A');
expect(zoneASpec.onScheduleTask).toHaveBeenCalled();
server.close(() => {
done();
});
},
);
req.end();
});
});
});
});