foreman_ansible
foreman_ansible copied to clipboard
Fixes #37245 - 25 tests failing with "TypeError: Cannot read property 'perPage' of undefined"
This pull-request fixes #37245 by wrapping the mocked context in a React state.
Detailed problem description
This bug was introduced, when useForemanContext
of ForemanContext.js was changed in theforeman/foreman@0b40a64be53fb54843bccf2aa193cab0632c83b3
In the commit, useForemanContext
was split into useForemanContext
and useForemanSetContext
, which return getForemanContext.context
and getForemanContext.setContext
respectively. context
and setContext
were provided by wrapping the original context object in React.useState()
.
In foreman_ansible, this change is not yet reflected. getForemanContext
still returns the raw context object. Since the context object does not have the fields context
and setContext
, useForemanContext
and useForemanSetContext
would return undefined
, causing the tests to fail.
This is fixed, by wrapping the context object given to getForemanContext
in withMockedProvider
of testHelper.js in React.useState()
similar to ReactApp.js of Foreman.