-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathconfig.js
More file actions
56 lines (46 loc) · 1.25 KB
/
config.js
File metadata and controls
56 lines (46 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {
getConfig as getConfigDTL,
configure as configureDTL,
} from '@testing-library/dom'
function jestFakeTimersAreEnabled() {
/* istanbul ignore else */
if (typeof jest !== 'undefined' && jest !== null) {
return (
// legacy timers
setTimeout._isMockFunction === true || // modern timers
// eslint-disable-next-line prefer-object-has-own -- No Object.hasOwn in all target environments we support.
Object.prototype.hasOwnProperty.call(setTimeout, 'clock')
)
} // istanbul ignore next
return false
}
function maybeAdvanceJestTimers(delay) {
if (jestFakeTimersAreEnabled()) {
jest.advanceTimersByTime(delay)
}
}
let configForRTL = {
reactStrictMode: false,
advanceTimers: maybeAdvanceJestTimers,
}
function getConfig() {
return {
...getConfigDTL(),
...configForRTL,
}
}
function configure(newConfig) {
if (typeof newConfig === 'function') {
// Pass the existing config out to the provided function
// and accept a delta in return
newConfig = newConfig(getConfig())
}
const {reactStrictMode, advanceTimers, ...configForDTL} = newConfig
configureDTL(configForDTL)
configForRTL = {
...configForRTL,
reactStrictMode,
advanceTimers,
}
}
export {getConfig, configure}