Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit d61a156

Browse files
feat: New strict option for React.Strict mode testing. (#415)
* Allow strict mode testing * Add example of strict mode
1 parent 592b337 commit d61a156

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

examples/react-scripts/src/App.cy-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as Child from './Child'
88

99
describe('App', () => {
1010
it('renders learn react link', () => {
11-
mount(<App />)
11+
mount(<App />, { strict: true })
1212
cy.contains(/Learn React/)
1313
})
1414

lib/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ interface MountReactComponentOptions {
5656
* true by default.
5757
*/
5858
log: boolean
59+
/**
60+
* Render component in React [strict mode](https://reactjs.org/docs/strict-mode.html)
61+
* It activates additional checks and warnings for child components.
62+
*/
63+
strict: boolean
5964
}
6065

6166
type MountOptions = Partial<StyleOptions & MountReactComponentOptions>

lib/mount.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ export const mount = (jsx: React.ReactElement, options: MountOptions = {}) => {
8888
key,
8989
}
9090

91-
const reactComponent = React.createElement(React.Fragment, props, jsx)
91+
const reactComponent = React.createElement(
92+
options.strict ? React.StrictMode : React.Fragment,
93+
props,
94+
jsx,
95+
)
9296
// since we always surround the component with a fragment
9397
// let's get back the original component
9498
// @ts-ignore

0 commit comments

Comments
 (0)