Files
splincode d35c17d393 refactor: correct typos in comments, docs, and error messages
Fix misspellings found across multiple packages:

- `paramters` → `parameters` (utils.spec.ts)
- `directve` → `directive` (typecheck/context.ts)
- `subscriper` → `subscriber` (zone.js rxjs test)
- `swich` → `switch` (adev animation parser test)
- `subscribtion` → `subscription` (forms/abstract_model.ts)
- `lifecyle` → `lifecycle` (ng-devtools-backend hooks)
- `compatability` → `compatibility` (tree-visualizer.ts)
- `indentifier(s)` → `identifier(s)` (compiler-cli shared.ts, i18n_helpers.ts, declaration_only_emission_spec.ts)
- `identifer` → `identifier` (platform-browser shared_styles_host.ts)
- `prcess` → `process` (standalone-migration to-standalone.ts)
2026-08-17 14:57:04 -07:00

113 lines
3.3 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 {fromEvent, fromEventPattern, Observable} from 'rxjs';
import {isBrowser} from '../../lib/common/utils';
import {ifEnvSupports} from '../test-util';
function isEventTarget() {
return isBrowser;
}
(isEventTarget as any).message = 'EventTargetTest';
describe('Observable.fromEvent', () => {
let log: any[];
const constructorZone1: Zone = Zone.current.fork({name: 'Constructor Zone1'});
const subscriptionZone: Zone = Zone.current.fork({name: 'Subscription Zone'});
const triggerZone: Zone = Zone.current.fork({name: 'Trigger Zone'});
let observable1: Observable<any>;
beforeEach(() => {
log = [];
});
it(
'fromEvent EventTarget func callback should run in the correct zone',
ifEnvSupports(isEventTarget, () => {
observable1 = constructorZone1.run(() => {
return fromEvent(document, 'click');
});
const clickEvent = document.createEvent('Event');
clickEvent.initEvent('click', true, true);
subscriptionZone.run(() => {
observable1.subscribe(
(result: any) => {
expect(Zone.current.name).toEqual(subscriptionZone.name);
log.push(result);
},
() => {
fail('should not call error');
},
() => {
expect(Zone.current.name).toEqual(subscriptionZone.name);
log.push('completed');
},
);
});
triggerZone.run(() => {
document.dispatchEvent(clickEvent);
});
expect(log).toEqual([clickEvent]);
}),
);
it(
'fromEventPattern EventTarget func callback should run in the correct zone',
ifEnvSupports(isEventTarget, () => {
const button = document.createElement('button');
document.body.appendChild(button);
observable1 = constructorZone1.run(() => {
return fromEventPattern(
(handler: any) => {
expect(Zone.current.name).toEqual(constructorZone1.name);
button.addEventListener('click', handler);
log.push('addListener');
},
(handler: any) => {
expect(Zone.current.name).toEqual(constructorZone1.name);
button.removeEventListener('click', handler);
document.body.removeChild(button);
log.push('removeListener');
},
);
});
const clickEvent = document.createEvent('Event');
clickEvent.initEvent('click', false, false);
const subscriber: any = subscriptionZone.run(() => {
return observable1.subscribe(
(result: any) => {
expect(Zone.current.name).toEqual(subscriptionZone.name);
log.push(result);
},
() => {
fail('should not call error');
},
() => {
expect(Zone.current.name).toEqual(subscriptionZone.name);
log.push('completed');
},
);
});
triggerZone.run(() => {
button.dispatchEvent(clickEvent);
subscriber.complete();
});
expect(log).toEqual(['addListener', clickEvent, 'completed', 'removeListener']);
}),
);
});