Skip to content

Commit 0880eba

Browse files
yinmeps1lon
andauthored
feat: add reactStrictMode option to enable strict mode render (#1241)
* feat: add `reactStrictMode` option and override `getConfig` and `configure` functions from DTL * feat: update types for overridden `getConfig` and `configure` functions * test: add tests for checking configure APIs support RTL option and do not degrade * refactor: use a wrapper option for simplicity * refactor: use same function for wrapping UI if needed * feat: enable strict mode render if `reactStrictMode` option is true * test: add tests for checking strict mode works and can be combine with wrapper --------- Co-authored-by: Sebastian Silbermann <[email protected]>
1 parent 03a301f commit 0880eba

File tree

8 files changed

+443
-174
lines changed

8 files changed

+443
-174
lines changed

Diff for: src/__tests__/__snapshots__/render.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`supports fragments 1`] = `
3+
exports[`render API supports fragments 1`] = `
44
<DocumentFragment>
55
<div>
66
<code>

Diff for: src/__tests__/config.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import {configure, getConfig} from '../'
2+
3+
describe('configuration API', () => {
4+
let originalConfig
5+
beforeEach(() => {
6+
// Grab the existing configuration so we can restore
7+
// it at the end of the test
8+
configure(existingConfig => {
9+
originalConfig = existingConfig
10+
// Don't change the existing config
11+
return {}
12+
})
13+
})
14+
15+
afterEach(() => {
16+
configure(originalConfig)
17+
})
18+
19+
describe('DTL options', () => {
20+
test('configure can set by a plain JS object', () => {
21+
const testIdAttribute = 'not-data-testid'
22+
configure({testIdAttribute})
23+
24+
expect(getConfig().testIdAttribute).toBe(testIdAttribute)
25+
})
26+
27+
test('configure can set by a function', () => {
28+
// setup base option
29+
const baseTestIdAttribute = 'data-testid'
30+
configure({testIdAttribute: baseTestIdAttribute})
31+
32+
const modifiedPrefix = 'modified-'
33+
configure(existingConfig => ({
34+
testIdAttribute: `${modifiedPrefix}${existingConfig.testIdAttribute}`,
35+
}))
36+
37+
expect(getConfig().testIdAttribute).toBe(
38+
`${modifiedPrefix}${baseTestIdAttribute}`,
39+
)
40+
})
41+
})
42+
43+
describe('RTL options', () => {
44+
test('configure can set by a plain JS object', () => {
45+
configure({reactStrictMode: true})
46+
47+
expect(getConfig().reactStrictMode).toBe(true)
48+
})
49+
50+
test('configure can set by a function', () => {
51+
configure(existingConfig => ({
52+
reactStrictMode: !existingConfig.reactStrictMode,
53+
}))
54+
55+
expect(getConfig().reactStrictMode).toBe(true)
56+
})
57+
})
58+
59+
test('configure can set DTL and RTL options at once', () => {
60+
const testIdAttribute = 'not-data-testid'
61+
configure({testIdAttribute, reactStrictMode: true})
62+
63+
expect(getConfig().testIdAttribute).toBe(testIdAttribute)
64+
expect(getConfig().reactStrictMode).toBe(true)
65+
})
66+
})

0 commit comments

Comments
 (0)