Skip to content

Commit e02d6ba

Browse files
committed
Add JSDoc to test-utils for better Intellisense when setting options in test files.
1 parent 6af87f3 commit e02d6ba

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

client/test-utils.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,30 @@ Providers.propTypes = {
6666
children: PropTypes.element.isRequired
6767
};
6868

69+
/**
70+
* @typedef {import('@testing-library/react').RenderOptions} RenderOptions
71+
* @typedef {import('@testing-library/react').RenderResult} RenderResult
72+
*/
73+
74+
/**
75+
* @typedef {object} CustomRenderOptions
76+
* @extends RenderOptions
77+
* @property {boolean} [mobile] - Can use options { mobile: true } or { mobile: false } to determine which `react-responsive` media queries will match.
78+
* @property {number} [deviceWidth] - Can set a specific device width, if testing more than 2 breakpoints. ie. { deviceWidth: 700 }
79+
*/
80+
81+
/**
82+
* @typedef {object} ReduxRenderOptions
83+
* @extends CustomRenderOptions
84+
* @property [initialState] - Can pass in a partial initialState for the Redux store, to be shallow merged with the default state. // TODO: deep merge
85+
* @property {import('redux').Store} [store] - Can use a custom store instance.
86+
*/
87+
88+
/**
89+
* @param {React.ReactElement} ui
90+
* @param {ReduxRenderOptions & CustomRenderOptions & RenderOptions} [options]
91+
* @return {RenderResult & { store: import('redux').Store }}
92+
*/
6993
function reduxRender(
7094
ui,
7195
{ initialState, store = configureStore(initialState), ...renderOptions } = {}
@@ -91,6 +115,11 @@ function reduxRender(
91115
return { store, ...render(ui, { wrapper: Wrapper, ...renderOptions }) };
92116
}
93117

118+
/**
119+
* @param {React.ReactElement} ui
120+
* @param {CustomRenderOptions & RenderOptions} [options]
121+
* @return {RenderResult}
122+
*/
94123
const customRender = (ui, options) =>
95124
// Pass options to Provider, see: https://github.com/testing-library/react-testing-library/issues/780#issuecomment-687525893
96125
render(ui, {

0 commit comments

Comments
 (0)