From e8dc843f78dcfac9905fbe9951c729685001f536 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Fri, 22 Oct 2021 10:49:53 -0400 Subject: [PATCH] Replace enzyme with React testing library in app and extension (#918) * Update tests * Replace in extension as well --- extension/package.json | 4 +- extension/test/app/containers/App.spec.js | 24 +- extension/test/setup.js | 5 +- packages/redux-devtools-app/package.json | 8 +- packages/redux-devtools-app/test/app.spec.tsx | 38 +- packages/redux-devtools-app/test/setup.ts | 5 +- .../src/ActionList.tsx | 7 +- .../src/DevtoolsInspector.tsx | 1 + yarn.lock | 437 ++++-------------- 9 files changed, 120 insertions(+), 409 deletions(-) diff --git a/extension/package.json b/extension/package.json index 29bd5500..251bc5c9 100644 --- a/extension/package.json +++ b/extension/package.json @@ -61,6 +61,8 @@ "@babel/preset-react": "^7.14.5", "@babel/preset-typescript": "^7.15.0", "@babel/register": "^7.15.3", + "@testing-library/jest-dom": "^5.14.1", + "@testing-library/react": "^12.1.2", "@types/chrome": "^0.0.159", "@types/lodash": "^4.14.176", "@types/react": "^16.14.18", @@ -74,8 +76,6 @@ "cross-env": "^7.0.3", "css-loader": "^6.4.0", "electron": "^15.3.0", - "enzyme": "^3.11.0", - "enzyme-adapter-react-16": "^1.15.6", "eslint": "^7.32.0", "eslint-config-airbnb": "^18.2.1", "eslint-plugin-import": "^2.25.2", diff --git a/extension/test/app/containers/App.spec.js b/extension/test/app/containers/App.spec.js index d7baf977..ffff097e 100644 --- a/extension/test/app/containers/App.spec.js +++ b/extension/test/app/containers/App.spec.js @@ -1,24 +1,30 @@ import React from 'react'; -import { mount } from 'enzyme'; +import { render, screen, within } from '@testing-library/react'; import { Provider } from 'react-redux'; import configureStore from '../../../src/app/stores/windowStore'; import App from '../../../src/app/containers/App'; const { store } = configureStore(store); -const component = mount( - - - -); describe('App container', () => { it("should render inspector monitor's component", () => { - expect(component.find('DevtoolsInspector').html()).toBeDefined(); + render( + + + + ); + expect(screen.getByTestId('inspector')).toBeDefined(); }); it('should contain an empty action list', () => { - expect(component.find('ActionList').html()).toMatch( - /
<\/div>/ + render( + + + ); + const actionList = screen.getByTestId('actionList'); + expect( + within(actionList).getByTestId('actionListRows') + ).toBeEmptyDOMElement(); }); }); diff --git a/extension/test/setup.js b/extension/test/setup.js index b85f2f1e..fef3c35e 100644 --- a/extension/test/setup.js +++ b/extension/test/setup.js @@ -1,8 +1,5 @@ require('@babel/polyfill'); global.chrome = require('sinon-chrome'); -import Enzyme from 'enzyme'; -import Adapter from 'enzyme-adapter-react-16'; - -Enzyme.configure({ adapter: new Adapter() }); +require('@testing-library/jest-dom'); jest.setTimeout(50000); diff --git a/packages/redux-devtools-app/package.json b/packages/redux-devtools-app/package.json index a3cb9044..819da553 100644 --- a/packages/redux-devtools-app/package.json +++ b/packages/redux-devtools-app/package.json @@ -67,8 +67,8 @@ "@babel/preset-react": "^7.14.5", "@babel/preset-typescript": "^7.15.0", "@rjsf/core": "^3.2.0", - "@types/enzyme": "^3.10.10", - "@types/enzyme-adapter-react-16": "^1.0.6", + "@testing-library/jest-dom": "^5.14.1", + "@testing-library/react": "^12.1.2", "@types/jest": "^27.0.2", "@types/jsan": "^3.1.2", "@types/json-schema": "^7.0.9", @@ -79,6 +79,7 @@ "@types/react-redux": "^7.1.20", "@types/socketcluster-client": "^13.0.5", "@types/styled-components": "^5.1.15", + "@types/testing-library__jest-dom": "^5.14.1", "@types/webpack": "^5.28.0", "@types/webpack-dev-server": "^4.3.1", "@types/webpack-env": "^1.16.3", @@ -86,9 +87,6 @@ "@typescript-eslint/parser": "^5.1.0", "babel-loader": "^8.2.3", "css-loader": "^6.4.0", - "enzyme": "^3.11.0", - "enzyme-adapter-react-16": "^1.15.6", - "enzyme-to-json": "^3.6.2", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-jest": "^25.2.2", diff --git a/packages/redux-devtools-app/test/app.spec.tsx b/packages/redux-devtools-app/test/app.spec.tsx index bcd7811f..615fb5b2 100644 --- a/packages/redux-devtools-app/test/app.spec.tsx +++ b/packages/redux-devtools-app/test/app.spec.tsx @@ -1,8 +1,7 @@ -import React, { Component } from 'react'; +import React from 'react'; import { Provider } from 'react-redux'; import { createStore, applyMiddleware } from 'redux'; -import { mount, ReactWrapper } from 'enzyme'; -// import { mountToJson } from 'enzyme-to-json'; +import { render, screen, within } from '@testing-library/react'; import App from '../src/containers/App'; import api from '../src/middlewares/api'; import exportState from '../src/middlewares/exportState'; @@ -10,39 +9,28 @@ import rootReducer from '../src/reducers'; import { DATA_TYPE_KEY } from '../src/constants/dataTypes'; import stringifyJSON from '../src/utils/stringifyJSON'; -let wrapper: ReactWrapper; - const store = createStore(rootReducer, applyMiddleware(exportState, api)); describe('App container', () => { - beforeAll(() => { - wrapper = mount( + it("should render inspector monitor's wrapper", () => { + render( ); - }); - - /* - it('should render the App', () => { - expect(mountToJson(wrapper)).toMatchSnapshot(); - }); -*/ - - it("should render inspector monitor's wrapper", () => { - expect(wrapper.find('DevtoolsInspector').html()).toBeDefined(); + expect(screen.getByTestId('inspector')).toBeDefined(); }); it('should contain an empty action list', () => { + render( + + + + ); + const actionList = screen.getByTestId('actionList'); expect( - wrapper - .find('ActionList') - .findWhere((n) => { - const { className } = n.props(); - return className && className.startsWith('actionListRows-'); - }) - .html() - ).toMatch(/
<\/div>/); + within(actionList).getByTestId('actionListRows') + ).toBeEmptyDOMElement(); }); }); diff --git a/packages/redux-devtools-app/test/setup.ts b/packages/redux-devtools-app/test/setup.ts index fc7b0dce..7b0828bf 100644 --- a/packages/redux-devtools-app/test/setup.ts +++ b/packages/redux-devtools-app/test/setup.ts @@ -1,4 +1 @@ -import Enzyme from 'enzyme'; -import Adapter from 'enzyme-adapter-react-16'; - -Enzyme.configure({ adapter: new Adapter() }); +import '@testing-library/jest-dom'; diff --git a/packages/redux-devtools-inspector-monitor/src/ActionList.tsx b/packages/redux-devtools-inspector-monitor/src/ActionList.tsx index 22085b0e..4362d2d6 100644 --- a/packages/redux-devtools-inspector-monitor/src/ActionList.tsx +++ b/packages/redux-devtools-inspector-monitor/src/ActionList.tsx @@ -140,6 +140,7 @@ export default class ActionList< return (
0} hasStagedActions={actionIds.length > 1} /> -
+
{filteredActionIds.map((actionId) => ( > extends PureComponent< return (
=2.2.1 || 3.x || 4 || 5, semver@npm:2 || 3 || 4 || 5, semver@npm:2.x || 3.x || 4 || 5, semver@npm:4 || 5, semver@npm:^2.3.0 || 3.x || 4 || 5, semver@npm:^5.0.3, semver@npm:^5.1.0, semver@npm:^5.3.0, semver@npm:^5.4.1, semver@npm:^5.5.0, semver@npm:^5.6.0, semver@npm:^5.7.0, semver@npm:^5.7.1": +"semver@npm:2 >=2.2.1 || 3.x || 4 || 5, semver@npm:2 || 3 || 4 || 5, semver@npm:2.x || 3.x || 4 || 5, semver@npm:4 || 5, semver@npm:^2.3.0 || 3.x || 4 || 5, semver@npm:^5.0.3, semver@npm:^5.1.0, semver@npm:^5.3.0, semver@npm:^5.4.1, semver@npm:^5.5.0, semver@npm:^5.6.0, semver@npm:^5.7.1": version: 5.7.1 resolution: "semver@npm:5.7.1" bin: @@ -27136,6 +26856,16 @@ resolve@^2.0.0-next.3: languageName: node linkType: hard +"source-map-resolve@npm:^0.6.0": + version: 0.6.0 + resolution: "source-map-resolve@npm:0.6.0" + dependencies: + atob: ^2.1.2 + decode-uri-component: ^0.2.0 + checksum: fe503b9e5dac1c54be835282fcfec10879434e7b3ee08a9774f230299c724a8d403484d9531276d1670c87390e0e4d1d3f92b14cca6e4a2445ea3016b786ecd4 + languageName: node + linkType: hard + "source-map-support@npm:^0.5.16, source-map-support@npm:^0.5.6, source-map-support@npm:~0.5.12, source-map-support@npm:~0.5.20": version: 0.5.20 resolution: "source-map-support@npm:0.5.20" @@ -27619,17 +27349,6 @@ resolve@^2.0.0-next.3: languageName: node linkType: hard -"string.prototype.trim@npm:^1.2.1": - version: 1.2.5 - resolution: "string.prototype.trim@npm:1.2.5" - dependencies: - call-bind: ^1.0.2 - define-properties: ^1.1.3 - es-abstract: ^1.19.1 - checksum: d9f748ffca2a3ce722c421f7c2993b6490ec0cf19d9cb0904598c744e9367e54a3f13c7b99c8c0966c8a76484bd656a60281daa5d0534cc222cd72193fd63034 - languageName: node - linkType: hard - "string.prototype.trimend@npm:^1.0.4": version: 1.0.4 resolution: "string.prototype.trimend@npm:1.0.4" @@ -28925,7 +28644,7 @@ resolve@^2.0.0-next.3: languageName: node linkType: hard -"tslib@npm:^2.0.0, tslib@npm:^2.0.1, tslib@npm:^2.0.3, tslib@npm:^2.1.0, tslib@npm:^2.2.0, tslib@npm:^2.3.0": +"tslib@npm:^2.0.0, tslib@npm:^2.0.1, tslib@npm:^2.0.3, tslib@npm:^2.1.0, tslib@npm:^2.3.0": version: 2.3.1 resolution: "tslib@npm:2.3.1" checksum: de17a98d4614481f7fcb5cd53ffc1aaf8654313be0291e1bfaee4b4bb31a20494b7d218ff2e15017883e8ea9626599b3b0e0229c18383ba9dce89da2adf15cb9