Skip to content

Commit 86a9b27

Browse files
committed
feat: add reactStrictMode option and override getConfig and configure functions from DTL
1 parent c04b8f0 commit 86a9b27

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/config.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {
2+
getConfig as getConfigDTL,
3+
configure as configureDTL,
4+
} from '@testing-library/dom'
5+
6+
let configForRTL = {
7+
reactStrictMode: false,
8+
}
9+
10+
function getConfig() {
11+
return {
12+
...getConfigDTL(),
13+
...configForRTL,
14+
}
15+
}
16+
17+
function configure(newConfig) {
18+
if (typeof newConfig === 'function') {
19+
// Pass the existing config out to the provided function
20+
// and accept a delta in return
21+
newConfig = newConfig(getConfig())
22+
}
23+
24+
const {reactStrictMode, ...configForDTL} = newConfig
25+
26+
configureDTL(configForDTL)
27+
28+
configForRTL = {
29+
...configForRTL,
30+
reactStrictMode,
31+
}
32+
}
33+
34+
export {getConfig, configure}

src/pure.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import act, {
1111
setReactActEnvironment,
1212
} from './act-compat'
1313
import {fireEvent} from './fire-event'
14+
import {getConfig, configure} from './config'
1415

1516
function jestFakeTimersAreEnabled() {
1617
/* istanbul ignore else */
@@ -276,6 +277,6 @@ function renderHook(renderCallback, options = {}) {
276277

277278
// just re-export everything from dom-testing-library
278279
export * from '@testing-library/dom'
279-
export {render, renderHook, cleanup, act, fireEvent}
280+
export {render, renderHook, cleanup, act, fireEvent, getConfig, configure}
280281

281282
/* eslint func-name-matching:0 */

0 commit comments

Comments
 (0)