File tree 1 file changed +56
-1
lines changed
1 file changed +56
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { fireEvent as dtlFireEvent } from '@testing-library/dom'
2
2
import act from './act-compat'
3
3
4
- const discreteEvents = new Set ( )
4
+ // https://github.com/facebook/react/blob/b48b38af68c27fd401fe4b923a8fa0b229693cd4/packages/react-dom/src/events/ReactDOMEventListener.js#L310-L366
5
+ const discreteEvents = new Set ( [
6
+ 'cancel' ,
7
+ 'click' ,
8
+ 'close' ,
9
+ 'contextmenu' ,
10
+ 'copy' ,
11
+ 'cut' ,
12
+ 'auxclick' ,
13
+ 'dblclick' ,
14
+ 'dragend' ,
15
+ 'dragstart' ,
16
+ 'drop' ,
17
+ 'focusin' ,
18
+ 'focusout' ,
19
+ 'input' ,
20
+ 'invalid' ,
21
+ 'keydown' ,
22
+ 'keypress' ,
23
+ 'keyup' ,
24
+ 'mousedown' ,
25
+ 'mouseup' ,
26
+ 'paste' ,
27
+ 'pause' ,
28
+ 'play' ,
29
+ 'pointercancel' ,
30
+ 'pointerdown' ,
31
+ 'pointerup' ,
32
+ 'ratechange' ,
33
+ 'reset' ,
34
+ 'seeked' ,
35
+ 'submit' ,
36
+ 'touchcancel' ,
37
+ 'touchend' ,
38
+ 'touchstart' ,
39
+ 'volumechange' ,
40
+ 'change' ,
41
+ 'selectionchange' ,
42
+ 'textInput' ,
43
+ 'compositionstart' ,
44
+ 'compositionend' ,
45
+ 'compositionupdate' ,
46
+ 'beforeblur' ,
47
+ 'afterblur' ,
48
+ 'beforeinput' ,
49
+ 'blur' ,
50
+ 'fullscreenchange' ,
51
+ 'focus' ,
52
+ 'hashchange' ,
53
+ 'popstate' ,
54
+ 'select' ,
55
+ 'selectstart' ,
56
+ ] )
5
57
function isDiscreteEvent ( type ) {
6
58
return discreteEvents . has ( type )
7
59
}
@@ -15,6 +67,9 @@ function noAct(cb) {
15
67
// we make this distinction however is because we have
16
68
// a few extra events that work a bit differently
17
69
function fireEvent ( element , event , ...args ) {
70
+ // `act` would simulate how this event would behave if dispatched from a React event listener.
71
+ // In almost all cases we want to simulate how this event behaves in response to a user interaction.
72
+ // See discussion in https://github.com/facebook/react/pull/21202
18
73
const eventWrapper = isDiscreteEvent ( event . type ) ? noAct : act
19
74
20
75
let fireEventReturnValue
You can’t perform that action at this time.
0 commit comments