Skip to content

Commit 225e4f2

Browse files
JiaLiPassionatscott
authored andcommitted
feat(core): triggerEventHandler accept optional eventObj (angular#45279)
Close angular#44724 `DebugNode.triggerEventHandler()` should accept the `eventObj` as an optional parameter. So the user don't have to write code like ``` elem.triggerEventHandler('click', null); ``` PR Close angular#45279
1 parent 89d71b5 commit 225e4f2

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

goldens/public-api/core/core.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export class DebugElement extends DebugNode {
320320
get styles(): {
321321
[key: string]: string | null;
322322
};
323-
triggerEventHandler(eventName: string, eventObj: any): void;
323+
triggerEventHandler(eventName: string, eventObj?: any): void;
324324
}
325325

326326
// @public (undocumented)

packages/core/src/debug/debug_node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ export class DebugElement extends DebugNode {
343343
*
344344
* @see [Testing components scenarios](guide/testing-components-scenarios#trigger-event-handler)
345345
*/
346-
triggerEventHandler(eventName: string, eventObj: any): void {
346+
triggerEventHandler(eventName: string, eventObj?: any): void {
347347
const node = this.nativeNode as any;
348348
const invokedListeners: Function[] = [];
349349

packages/core/test/debug/debug_node_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,11 +978,11 @@ class TestCmptWithPropInterpolation {
978978
const button = fixture.debugElement.query(By.css('button'));
979979

980980
expect(() => {
981-
button.triggerEventHandler('click', null);
981+
button.triggerEventHandler('click');
982982
fixture.detectChanges();
983983
}).not.toThrow();
984984

985-
expect(value).toBeNull();
985+
expect(value).toBeUndefined();
986986
});
987987

988988
describe('componentInstance on DebugNode', () => {

packages/forms/test/reactive_integration_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3458,7 +3458,7 @@ const ValueAccessorB = createControlValueAccessor('[cva-b]');
34583458
const inputNativeEl = inputEl.nativeElement;
34593459
expect(inputNativeEl.value).toEqual('oldValue');
34603460

3461-
inputEl.triggerEventHandler('compositionstart', null);
3461+
inputEl.triggerEventHandler('compositionstart');
34623462

34633463
inputNativeEl.value = 'updatedValue';
34643464
dispatchEvent(inputNativeEl, 'input');
@@ -3489,7 +3489,7 @@ const ValueAccessorB = createControlValueAccessor('[cva-b]');
34893489
const inputNativeEl = inputEl.nativeElement;
34903490
expect(inputNativeEl.value).toEqual('oldValue');
34913491

3492-
inputEl.triggerEventHandler('compositionstart', null);
3492+
inputEl.triggerEventHandler('compositionstart');
34933493

34943494
inputNativeEl.value = 'updatedValue';
34953495
dispatchEvent(inputNativeEl, 'input');
@@ -3517,7 +3517,7 @@ const ValueAccessorB = createControlValueAccessor('[cva-b]');
35173517
const inputNativeEl = inputEl.nativeElement;
35183518
expect(inputNativeEl.value).toEqual('oldValue');
35193519

3520-
inputEl.triggerEventHandler('compositionstart', null);
3520+
inputEl.triggerEventHandler('compositionstart');
35213521

35223522
inputNativeEl.value = 'updatedValue';
35233523
dispatchEvent(inputNativeEl, 'input');

packages/forms/test/template_integration_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,7 +2511,7 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat
25112511
tick();
25122512
expect(inputNativeEl.value).toEqual('oldValue');
25132513

2514-
inputEl.triggerEventHandler('compositionstart', null);
2514+
inputEl.triggerEventHandler('compositionstart');
25152515

25162516
inputNativeEl.value = 'updatedValue';
25172517
dispatchEvent(inputNativeEl, 'input');
@@ -2546,7 +2546,7 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat
25462546
tick();
25472547
expect(inputNativeEl.value).toEqual('oldValue');
25482548

2549-
inputEl.triggerEventHandler('compositionstart', null);
2549+
inputEl.triggerEventHandler('compositionstart');
25502550

25512551
inputNativeEl.value = 'updatedValue';
25522552
dispatchEvent(inputNativeEl, 'input');
@@ -2578,7 +2578,7 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat
25782578
tick();
25792579
expect(inputNativeEl.value).toEqual('oldValue');
25802580

2581-
inputEl.triggerEventHandler('compositionstart', null);
2581+
inputEl.triggerEventHandler('compositionstart');
25822582

25832583
inputNativeEl.value = 'updatedValue';
25842584
dispatchEvent(inputNativeEl, 'input');

0 commit comments

Comments
 (0)