Skip to content

Commit 1fd4ee7

Browse files
committed
Get UI unit tests working again w latest enzyme pkg
For whatever reason, the latest version of Enzyme requires an `Adapter` to be configured. We also run the linting before the unit tests since linting can actually catch errors in the code before they cause the unit tests to fail.
1 parent 1eea138 commit 1fd4ee7

File tree

13 files changed

+45
-22
lines changed

13 files changed

+45
-22
lines changed

web-server/v0.4/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"dva": "^2.4.1",
3232
"dva-core": "^1.1.0",
3333
"enquire-js": "^0.2.1",
34+
"enzyme-adapter-react-16": "^1.15.1",
3435
"html2canvas": "^1.0.0-alpha.12",
3536
"jschart": "^1.0.7",
3637
"jspdf": "^1.5.3",
@@ -60,7 +61,7 @@
6061
"babel-eslint": "9.x",
6162
"cross-env": "^5.1.1",
6263
"cross-port-killer": "^1.0.1",
63-
"enzyme": "^3.1.0",
64+
"enzyme": "3.10.0",
6465
"eslint": "^5.0.0",
6566
"eslint-config-airbnb": "^17.0.0",
6667
"eslint-config-prettier": "^6.0.0",

web-server/v0.4/src/components/Button/index.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { shallow, configure } from 'enzyme';
3+
import Adapter from 'enzyme-adapter-react-16';
34
import Button from './index';
45

56
const mockProps = {
@@ -10,6 +11,7 @@ const mockProps = {
1011
};
1112

1213
const mockDispatch = jest.fn();
14+
configure({ adapter: new Adapter() });
1315
const wrapper = shallow(<Button dispatch={mockDispatch} {...mockProps} />);
1416

1517
describe('test rendering of Button component', () => {

web-server/v0.4/src/components/RowSelection/index.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { shallow, configure } from 'enzyme';
3+
import Adapter from 'enzyme-adapter-react-16';
34
import RowSelection from './index';
45
import Button from '../Button';
56

@@ -11,6 +12,7 @@ const mockProps = {
1112
};
1213

1314
const mockDispatch = jest.fn();
15+
configure({ adapter: new Adapter() });
1416
const wrapper = shallow(<RowSelection dispatch={mockDispatch} {...mockProps} />, {
1517
lifecycleExperimental: true,
1618
});

web-server/v0.4/src/components/Table/index.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { shallow, configure } from 'enzyme';
3+
import Adapter from 'enzyme-adapter-react-16';
34
import Table from './index';
45

56
const mockProps = {
@@ -9,6 +10,7 @@ const mockProps = {
910
};
1011

1112
const mockDispatch = jest.fn();
13+
configure({ adapter: new Adapter() });
1214
const wrapper = shallow(<Table dispatch={mockDispatch} {...mockProps} />);
1315

1416
describe('test rendering of Table component', () => {

web-server/v0.4/src/components/TableFilterSelection/index.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { shallow, configure } from 'enzyme';
3+
import Adapter from 'enzyme-adapter-react-16';
34
import TableFilterSelection from './index';
45
import Button from '../Button';
56

@@ -18,6 +19,7 @@ const mockProps = {
1819
};
1920

2021
const mockDispatch = jest.fn();
22+
configure({ adapter: new Adapter() });
2123
const wrapper = shallow(<TableFilterSelection dispatch={mockDispatch} {...mockProps} />, {
2224
lifecycleExperimental: true,
2325
});

web-server/v0.4/src/components/TimeseriesGraph/index.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { shallow, mount } from 'enzyme';
2+
import { shallow, mount, configure } from 'enzyme';
3+
import Adapter from 'enzyme-adapter-react-16';
34
import TimeseriesGraph from './index';
45

56
const mockProps = {
@@ -22,6 +23,7 @@ jest.mock('jschart', () => ({
2223
return 'true';
2324
}),
2425
}));
26+
configure({ adapter: new Adapter() });
2527
const wrapper = shallow(<TimeseriesGraph dispatch={mockDispatch} {...mockProps} />, {
2628
lifecycleExperimental: true,
2729
});

web-server/v0.4/src/pages/ComparisonSelect/index.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { shallow, configure } from 'enzyme';
3+
import Adapter from 'enzyme-adapter-react-16';
34

45
import ComparisonSelect from './index';
56
import PageHeaderLayout from '../../layouts/PageHeaderLayout';
@@ -12,6 +13,7 @@ const mockProps = {
1213
};
1314

1415
const mockDispatch = jest.fn();
16+
configure({ adapter: new Adapter() });
1517
const wrapper = shallow(
1618
<ComparisonSelect.WrappedComponent dispatch={mockDispatch} {...mockProps} />,
1719
{ disableLifecycleMethods: true }

web-server/v0.4/src/pages/Controllers/index.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { shallow, configure } from 'enzyme';
3+
import Adapter from 'enzyme-adapter-react-16';
34
import Controllers from './index';
45

56
import Table from '@/components/Table';
@@ -13,6 +14,7 @@ const mockProps = {
1314
};
1415

1516
const mockDispatch = jest.fn();
17+
configure({ adapter: new Adapter() });
1618
const wrapper = shallow(<Controllers.WrappedComponent dispatch={mockDispatch} {...mockProps} />, {
1719
disableLifecycleMethods: true,
1820
});

web-server/v0.4/src/pages/Results/index.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { shallow, configure } from 'enzyme';
3+
import Adapter from 'enzyme-adapter-react-16';
34
import Results from './index';
45

56
import Table from '@/components/Table';
@@ -11,6 +12,7 @@ const mockProps = {
1112
};
1213

1314
const mockDispatch = jest.fn();
15+
configure({ adapter: new Adapter() });
1416
const wrapper = shallow(<Results.WrappedComponent dispatch={mockDispatch} {...mockProps} />, {
1517
disableLifecycleMethods: true,
1618
});

web-server/v0.4/src/pages/RunComparison/index.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { shallow, configure } from 'enzyme';
3+
import Adapter from 'enzyme-adapter-react-16';
34
import 'jest-canvas-mock';
45

56
import RunComparison from './index';
@@ -31,6 +32,7 @@ clusterLabels.sample_metric = ['sample-1'];
3132
const selectedConfig = ['benchmark-sample-1'];
3233

3334
const mockDispatch = jest.fn();
35+
configure({ adapter: new Adapter() });
3436
const wrapper = shallow(
3537
<RunComparison.WrappedComponent dispatch={mockDispatch} location={mockLocation} {...mockProps} />,
3638
{ disableLifecycleMethods: true }

0 commit comments

Comments
 (0)