Skip to content

Commit 644f592

Browse files
committed
test: add tests for checking configure APIs support RTL option and do not degrade
1 parent a5ccabe commit 644f592

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/__tests__/config.js

Lines changed: 66 additions & 0 deletions
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)