@@ -100,7 +100,15 @@ export class UnitTestElement implements TestElement {
100
100
async click (
101
101
...args : [ ModifierKeys ?] | [ 'center' , ModifierKeys ?] | [ number , number , ModifierKeys ?]
102
102
) : Promise < void > {
103
- await this . _dispatchMouseEventSequence ( 'click' , args , 0 ) ;
103
+ const isDisabled = ( this . element as Partial < { disabled ?: boolean } > ) . disabled === true ;
104
+
105
+ // If the element is `disabled` and has a `disabled` property, we emit the mouse event
106
+ // sequence but not dispatch the `click` event. This is necessary to keep the behavior
107
+ // consistent with an actual user interaction. The click event is not necessarily
108
+ // automatically prevented by the browser. There is mismatch between Firefox and Chromium:
109
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=329509.
110
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=1115661.
111
+ await this . _dispatchMouseEventSequence ( isDisabled ? null : 'click' , args , 0 ) ;
104
112
await this . _stabilize ( ) ;
105
113
}
106
114
@@ -284,9 +292,12 @@ export class UnitTestElement implements TestElement {
284
292
}
285
293
}
286
294
287
- /** Dispatches all the events that are part of a mouse event sequence. */
295
+ /**
296
+ * Dispatches all the events that are part of a mouse event sequence
297
+ * and then emits a given primary event at the end, if speciifed.
298
+ */
288
299
private async _dispatchMouseEventSequence (
289
- name : string ,
300
+ primaryEventName : string | null ,
290
301
args : [ ModifierKeys ?] | [ 'center' , ModifierKeys ?] | [ number , number , ModifierKeys ?] ,
291
302
button ?: number ,
292
303
) {
@@ -313,11 +324,16 @@ export class UnitTestElement implements TestElement {
313
324
dispatchMouseEvent ( this . element , 'mousedown' , clientX , clientY , button , modifiers ) ;
314
325
this . _dispatchPointerEventIfSupported ( 'pointerup' , clientX , clientY , button ) ;
315
326
dispatchMouseEvent ( this . element , 'mouseup' , clientX , clientY , button , modifiers ) ;
316
- dispatchMouseEvent ( this . element , name , clientX , clientY , button , modifiers ) ;
327
+
328
+ // If a primary event name is specified, emit it after the mouse event sequence.
329
+ if ( primaryEventName !== null ) {
330
+ dispatchMouseEvent ( this . element , primaryEventName , clientX , clientY , button , modifiers ) ;
331
+ }
317
332
318
333
// This call to _stabilize should not be needed since the callers will already do that them-
319
334
// selves. Nevertheless it breaks some tests in g3 without it. It needs to be investigated
320
335
// why removing breaks those tests.
336
+ // See: https://github.com/angular/components/pull/20758/files#r520886256.
321
337
await this . _stabilize ( ) ;
322
338
}
323
339
}
0 commit comments