Skip to content

Commit 8e17e12

Browse files
fix: add react 18 support, fixes #728 (#729)
* fix: add react 18 support, fixes #728 * fix: Use react 18 to execute the tests suite Also replace the outdated enzyme by @testing-libray/react * fix: explicitly use last version of each major version for smoke tests Co-authored-by: Armand Abric <[email protected]>
1 parent a589fb2 commit 8e17e12

File tree

5 files changed

+206
-594
lines changed

5 files changed

+206
-594
lines changed

.github/workflows/continuous-integration.yaml

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ jobs:
2727
- run: yarn run smoke esm 15.6.2
2828
- run: yarn run smoke cjs 16.7.0
2929
- run: yarn run smoke esm 16.7.0
30-
- run: yarn run smoke cjs 17.0.1
31-
- run: yarn run smoke esm 17.0.1
30+
- run: yarn run smoke cjs 17.0.2
31+
- run: yarn run smoke esm 17.0.2
32+
- run: yarn run smoke cjs 18.0.0
33+
- run: yarn run smoke esm 18.0.0
34+
- run: yarn run smoke cjs 18.1.0
35+
- run: yarn run smoke esm 18.1.0
3236
- run: yarn run smoke cjs latest
3337
- run: yarn run smoke esm latest
3438
- run: yarn run smoke cjs next

package.json

+10-15
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@
2424
"smoke": "node tests/smoke/run"
2525
},
2626
"lint-staged": {
27-
"*.js": [
28-
"prettier --write \"**/*.{js,json}\"",
29-
"git add"
30-
]
27+
"*.js": ["prettier --write \"**/*.{js,json}\"", "git add"]
3128
},
3229
"author": {
3330
"name": "Algolia, Inc.",
@@ -43,13 +40,13 @@
4340
"@babel/preset-react": "7.16.7",
4441
"@commitlint/cli": "8.3.6",
4542
"@commitlint/config-angular": "8.3.6",
43+
"@testing-library/jest-dom": "^5.16.4",
44+
"@testing-library/react": "^13.2.0",
4645
"babel-eslint": "10.1.0",
4746
"babel-jest": "24.9.0",
4847
"babel-register": "6.26.0",
4948
"conventional-changelog-cli": "2.2.2",
5049
"doctoc": "1.4.0",
51-
"enzyme": "3.11.0",
52-
"enzyme-adapter-react-16": "1.15.6",
5350
"eslint": "6.8.0",
5451
"eslint-config-algolia": "14.0.1",
5552
"eslint-config-prettier": "6.15.0",
@@ -67,9 +64,9 @@
6764
"lint-staged": "10.5.4",
6865
"mversion": "2.0.1",
6966
"prettier": "1.19.1",
70-
"react": "16.14.0",
71-
"react-dom": "16.14.0",
72-
"react-test-renderer": "16.14.0",
67+
"react": "^18.1.0",
68+
"react-dom": "^18.1.0",
69+
"react-test-renderer": "^18.1.0",
7370
"rollup": "2.70.1",
7471
"rollup-plugin-babel": "4.4.0",
7572
"rollup-plugin-node-builtins": "2.1.2",
@@ -78,17 +75,15 @@
7875
"rollup-plugin-sourcemaps": "0.6.3"
7976
},
8077
"peerDependencies": {
81-
"react": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1",
82-
"react-dom": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1"
78+
"react": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1 || ^18.0.0",
79+
"react-dom": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1 || ^18.0.0"
8380
},
8481
"dependencies": {
8582
"@base2/pretty-print-object": "1.0.1",
8683
"is-plain-object": "5.0.0",
87-
"react-is": "17.0.2"
84+
"react-is": "18.1.0"
8885
},
8986
"jest": {
90-
"setupFilesAfterEnv": [
91-
"<rootDir>tests/setupTests.js"
92-
]
87+
"setupFilesAfterEnv": ["<rootDir>tests/setupTests.js"]
9388
}
9489
}

src/index.spec.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import React, { Fragment, Component } from 'react';
1010
import { createRenderer } from 'react-test-renderer/shallow';
11-
import { mount } from 'enzyme';
11+
import { render, screen } from '@testing-library/react';
1212
import reactElementToJSXString, { preserveFunctionLineBreak } from './index';
1313
import AnonymousStatelessComponent from './AnonymousStatelessComponent';
1414

@@ -1132,18 +1132,22 @@ describe('reactElementToJSXString(ReactElement)', () => {
11321132
<div>
11331133
{insideString}
11341134

1135-
<div id="hello" />
1135+
<div>Hello world!</div>
11361136

11371137
<p>Start editing to see some magic happen :)</p>
11381138
</div>
11391139
);
11401140
}
11411141
}
1142-
expect(mount(<App />).find('#hello')).toHaveLength(1);
1142+
1143+
render(<App />);
1144+
1145+
expect(screen.getByText('Hello world!')).toBeInTheDocument();
11431146
});
11441147

11451148
it('should not cause recursive loop when an element contains a ref', () => {
1146-
expect.assertions(1);
1149+
expect.assertions(2);
1150+
11471151
class App extends Component {
11481152
constructor(props) {
11491153
super(props);
@@ -1159,10 +1163,18 @@ describe('reactElementToJSXString(ReactElement)', () => {
11591163
);
11601164
}
11611165
render() {
1162-
return <input ref={this.inputRef} />;
1166+
return (
1167+
<>
1168+
<input ref={this.inputRef} />
1169+
<div>Hello world!</div>
1170+
</>
1171+
);
11631172
}
11641173
}
1165-
mount(<App />);
1174+
1175+
render(<App />);
1176+
1177+
expect(screen.getByText('Hello world!')).toBeInTheDocument();
11661178
});
11671179

11681180
it('should use inferred function name as display name for `forwardRef` element', () => {

tests/setupTests.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
import Enzyme from 'enzyme';
2-
import Adapter from 'enzyme-adapter-react-16';
3-
4-
Enzyme.configure({ adapter: new Adapter() });
1+
import '@testing-library/jest-dom';

0 commit comments

Comments
 (0)