-
Notifications
You must be signed in to change notification settings - Fork 10
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
isReady prop passed to children of SplitTreatments is never true during unit tests #13
Comments
isReady
prop passed to children of SplitTreatments
is never true
during unit tests
Hi Brent, since react SDK only runs in client side, can you add the section below to package.json and see if it fixes the issue: |
Hi Brent, just following up on this issue, do you still need help? Thanks |
Hi Brent, just want to let you know, I can repro this issue and currently we are working on a fix. Thanks |
Hi Brent, we have a workaround, basically we need to refresh the rendering for the wrapper object since the first initial render is the first initial values for the props, see below: expect(wrapper.html().includes(expectedText)).toBe(false); The sample test script is attached, let me know if you have any questions. Thanks |
Hello @brentcklein , Also, as Bilal suggested here you must set the Since your example project was created via In summary, you should follow these steps in the root of your example https://github.com/brentcklein/split-tests: After that, Thanks, |
I'm having the exact same issue and none of the solutions above worked for me. I don't know if you realized that @brentcklein is using React Testing Library and the provided solution was using enzyme? I'm using RTL too and the isReady property is always false. Any tip on how to solve this? |
Hi @nunosimoes-tdx, Did you eject your project and set the test to run on browser mode? This is a required step to get the test to work. Thanks |
Hi @chillaq, thanks for you reply. |
I see that since 26.0.0 version of jest, the browser flag was deprecated. We tried to use the recommended browser-resolve but we blocked in one issue that was already reported without any feedback (jestjs/jest#10547). Seems that we need to rethink our strategy on unit testing with react split lib. |
hi @brentcklein , @nunosimoes-tdx It has been a while, but we have finally released v1.2.4 of the React SDK, which includes an update to solve the issues you were facing when using Jest for unit testing. Now it is not required to configure Jest with neither the browser option or browser-resolve. In other words, you can now use the default Jest configuration, provided, for example, by create-react-app projects. Please, let us know if you need further details. |
I'm experiencing this problem using v1.2.4 of the React SDK, but with a slight twist. If I have just one test in my test file then it passes (isReady changes to true). However, if I have more than one test, the first one passes but subsequent ones fail (isReady never changes to true). Because the tests each render |
Hi @RobertGardner, Thank you for your comment. It led us to an issue with the localhost mode in our JS SDK, which is used by the React SDK. Basically, SDK factory instances in localhost mode were all sharing the same reference to the mocked features and events were only emitted for the first instance. For react, check React SDK v1.2.6). It should solve your problem with Thanks, |
@EmilianoSanchez |
Summary
During normal rendering in
localhost
mode,SplitTreatments
first passesisReady: false
to its children and returns the control treatment, but shortly after returnsisReady: true
and returns the treatment defined inconfig.features
as expected. But during testing usingjest
andtesting-library/react
,isReady
is alwaysfalse
.I've set up a simple repository to reproduce the issue here: https://github.com/brentcklein/split-tests
Environment
yarn: 1.21.1
node: v14.4.0
react: 16.13.1
react-scripts: 3.4.1
jest: 24.9.0
testing-library/react: 9.5.0
splitio-react: 1.1.0
Example code
The splits render correctly when run with
yarn start
, but running the unit test results inUnable to find an element with the text: Split test-feature-on is on.
with the container output beingThe text was updated successfully, but these errors were encountered: