-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathconfig.js
66 lines (53 loc) · 1.8 KB
/
config.js
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
57
58
59
60
61
62
63
64
65
66
import {configure, getConfig} from '../'
describe('configuration API', () => {
let originalConfig
beforeEach(() => {
// Grab the existing configuration so we can restore
// it at the end of the test
configure(existingConfig => {
originalConfig = existingConfig
// Don't change the existing config
return {}
})
})
afterEach(() => {
configure(originalConfig)
})
describe('DTL options', () => {
test('configure can set by a plain JS object', () => {
const testIdAttribute = 'not-data-testid'
configure({testIdAttribute})
expect(getConfig().testIdAttribute).toBe(testIdAttribute)
})
test('configure can set by a function', () => {
// setup base option
const baseTestIdAttribute = 'data-testid'
configure({testIdAttribute: baseTestIdAttribute})
const modifiedPrefix = 'modified-'
configure(existingConfig => ({
testIdAttribute: `${modifiedPrefix}${existingConfig.testIdAttribute}`,
}))
expect(getConfig().testIdAttribute).toBe(
`${modifiedPrefix}${baseTestIdAttribute}`,
)
})
})
describe('RTL options', () => {
test('configure can set by a plain JS object', () => {
configure({reactStrictMode: true})
expect(getConfig().reactStrictMode).toBe(true)
})
test('configure can set by a function', () => {
configure(existingConfig => ({
reactStrictMode: !existingConfig.reactStrictMode,
}))
expect(getConfig().reactStrictMode).toBe(true)
})
})
test('configure can set DTL and RTL options at once', () => {
const testIdAttribute = 'not-data-testid'
configure({testIdAttribute, reactStrictMode: true})
expect(getConfig().testIdAttribute).toBe(testIdAttribute)
expect(getConfig().reactStrictMode).toBe(true)
})
})