Sp-dev-fx-webparts: react-test-renderer version for react 16.3.2

Created on 27 Nov 2018  路  9Comments  路  Source: pnp/sp-dev-fx-webparts

  • [x] Question
  • [ ] Bug
  • [ ] Enhancement

What version of react-test-renderer is required with react 16.3.2? After updating react from 15.6.2 to 16.3.2 as a part of SPFx version upgrade to 1.7.0, my react tests are failing with error Cannot find module 'react/lib/React' from 'ReactShallowRenderer.js'. Currently I am using "react-test-renderer": "15.5.4". Should I update the packages:

"@types/enzyme": "3.1.11",
"@types/enzyme-adapter-react-15": "1.0.2",
"enzyme": "3.3.0",
"enzyme-adapter-react-15": "1.7.0",

Most helpful comment

Thank you so much!

All 9 comments

Do you refer to the react-jest-testing sample?

@VelinGeorgiev Yes

I will try to upgrade the sample next week and let you know if i was able to reproduce it and fix it.

Hi @xyz92, I have created a pull request to upgrade the jest sample to SPFx 1.7. You can see how I changed the code here https://github.com/SharePoint/sp-dev-fx-webparts/pull/720.

You can have a look at the packages. json and see how I upgraded them, but also you will have to change the enzyme and enzyme adapter to support react 16 as you correctly assumed.

You will have to replace the "enzyme-adapter-react-15" with "enzyme-adapter-react-16" package and also upgrade enzyme to 3.8. Here is how I changed these packages:

"@types/enzyme": "3.1.15",
"enzyme": "3.8.0",
"enzyme-adapter-react-16": "1.7.1",

Once you do npm i, you will have to change

import * as Adapter from 'enzyme-adapter-react-15';

with

import * as Adapter from 'enzyme-adapter-react-16';

in your test files.

You can follow the pull request changes and see the changes I made to make it work with 1.7. Let me know if you still have questions.

Appreciate your help. Thank you!

Could you please share the steps you followed to upgrade SPFx to 1.7.0? Thank you!

@xyz92, I am using the Office 365 CLI to do that. Here is a blog post on how to use it https://blog.mastykarz.nl/upgrade-sharepoint-framework-project-office-365-cli/.

After you upgrade the solution, you will have to in addition manually upgrade the enzyme packages and tests imports to make them work with react 16.

Thank you so much!

@VelinGeorgiev What version of npm and node are you using for SPFx 1.7.0?

@xyz92

C:\Projects
位 node -v
v8.9.4

C:\Projects
位 npm -v
5.5.1
Was this page helpful?
0 / 5 - 0 ratings