Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add reactStrictMode option to enable strict mode render #1241

Merged
merged 8 commits into from
Jan 30, 2024
2 changes: 1 addition & 1 deletion src/__tests__/__snapshots__/render.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`supports fragments 1`] = `
exports[`render API supports fragments 1`] = `
<DocumentFragment>
<div>
<code>
Expand Down
66 changes: 66 additions & 0 deletions src/__tests__/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
})
})
Loading
Loading