Skip to content

Commit 3ce1fc3

Browse files
authored
feat: supporting react 17 (#83)
* feat: expanding support for react 17 * chore(deps-dev): bumping out of date dev deps * ci: running tests on react 16 and 17 * ci: fix indent problem
1 parent b324f05 commit 3ce1fc3

File tree

8 files changed

+629
-1365
lines changed

8 files changed

+629
-1365
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
node-version: [12.x, 14.x, 16.x]
10+
node-version: [14.x, 16.x]
11+
react: [16, 17]
12+
13+
name: build (${{ matrix.node-version }} w/ React ${{ matrix.react }}
1114

1215
steps:
1316
- uses: actions/checkout@v3
@@ -25,5 +28,9 @@ jobs:
2528
- name: Install deps
2629
run: npm ci
2730

31+
- name: Install React 16
32+
if: matrix.react == '16'
33+
run: npm i react@${{ matrix.react }} react-dom@${{ matrix.react }}
34+
2835
- name: Run tests
2936
run: npm test

__tests__/.eslintrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"extends": "@readme/eslint-config/testing"
2+
"extends": "@readme/eslint-config/testing",
3+
"rules": {
4+
"testing-library/no-container": "off",
5+
"testing-library/no-node-access": "off"
6+
}
37
}

__tests__/index.test.jsx

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const React = require('react');
2-
const { shallow } = require('enzyme');
2+
const { fireEvent, render } = require('@testing-library/react');
33

44
const { Variable, VARIABLE_REGEXP } = require('../index');
55

@@ -13,45 +13,47 @@ describe('single variable', () => {
1313
};
1414

1515
it('should render value', () => {
16-
const variable = shallow(<Variable {...props} />);
16+
const { container } = render(<Variable {...props} />);
1717

18-
expect(variable.text()).toBe('123456');
18+
expect(container).toHaveTextContent('123456');
1919
});
2020

2121
it('should render default if value not set', () => {
22-
const variable = shallow(<Variable {...props} defaults={[{ name: 'apiKey', default: 'default' }]} user={{}} />);
22+
const { container } = render(<Variable {...props} defaults={[{ name: 'apiKey', default: 'default' }]} user={{}} />);
2323

24-
expect(variable.text()).toBe('default');
24+
expect(container).toHaveTextContent('default');
2525
});
2626

2727
it('should render uppercase if no value and no default', () => {
28-
const variable = shallow(<Variable {...props} defaults={[]} user={{}} />);
28+
const { container } = render(<Variable {...props} defaults={[]} user={{}} />);
2929

30-
expect(variable.text()).toBe('APIKEY');
30+
expect(container).toHaveTextContent('APIKEY');
3131
});
3232

3333
it('should render auth dropdown if default and oauth enabled', () => {
34-
const variable = shallow(
34+
const { container } = render(
3535
<Variable {...props} defaults={[{ name: 'apiKey', default: 'default' }]} oauth user={{}} />
3636
);
37-
variable.find('.variable-underline').simulate('click');
3837

39-
expect(variable.find('#loginDropdown')).toHaveLength(1);
38+
fireEvent.click(container.querySelector('.variable-underline'));
39+
40+
expect(container.querySelectorAll('#loginDropdown')).toHaveLength(1);
4041
});
4142

4243
it('should render auth dropdown if no default and oauth enabled', () => {
43-
const variable = shallow(<Variable {...props} defaults={[]} oauth user={{}} />);
44-
variable.find('.variable-underline').simulate('click');
44+
const { container } = render(<Variable {...props} defaults={[]} oauth user={{}} />);
45+
46+
fireEvent.click(container.querySelector('.variable-underline'));
4547

46-
expect(variable.find('#loginDropdown')).toHaveLength(1);
48+
expect(container.querySelectorAll('#loginDropdown')).toHaveLength(1);
4749
});
4850

4951
it.todo('should set `selected` if nothing is selected');
5052

5153
it('should render objects as strings', () => {
52-
const variable = shallow(<Variable {...props} user={{ apiKey: { renderTo: 'string' } }} />);
54+
const { container } = render(<Variable {...props} user={{ apiKey: { renderTo: 'string' } }} />);
5355

54-
expect(variable.text()).toBe(JSON.stringify({ renderTo: 'string' }));
56+
expect(container).toHaveTextContent(JSON.stringify({ renderTo: 'string' }));
5557
});
5658
});
5759

@@ -70,32 +72,34 @@ describe('multiple variables', () => {
7072
};
7173

7274
it('should render the first of multiple values', () => {
73-
const variable = shallow(<Variable {...props} />);
75+
const { container } = render(<Variable {...props} />);
7476

75-
expect(variable.text()).toBe('123');
77+
expect(container).toHaveTextContent('123');
7678
});
7779

7880
it('should render whatever the selected name is', () => {
79-
const variable = shallow(<Variable {...props} selected="project2" />);
81+
const { container } = render(<Variable {...props} selected="project2" />);
8082

81-
expect(variable.text()).toBe('456');
83+
expect(container).toHaveTextContent('456');
8284
});
8385

8486
it('should show dropdown when clicked', () => {
85-
const variable = shallow(<Variable {...props} selected="project2" />);
87+
const { container } = render(<Variable {...props} selected="project2" />);
8688

87-
variable.find('.variable-underline').simulate('click');
89+
fireEvent.click(container.querySelector('.variable-underline'));
8890

89-
expect(variable.find('select option').map(el => el.text())).toStrictEqual(['project1', 'project2']);
91+
const options = [];
92+
container.querySelectorAll('select option').forEach(tk => {
93+
options.push(tk.text);
94+
});
95+
96+
expect(options).toStrictEqual(['project1', 'project2']);
9097
});
9198

9299
it('should select value when clicked', () => {
93-
let called = false;
94-
function changeSelected(selected) {
95-
expect(selected).toBe('project2');
96-
called = true;
97-
}
98-
const variable = shallow(
100+
const changeSelected = jest.fn();
101+
102+
const { container } = render(
99103
<Variable
100104
{...props}
101105
changeSelected={changeSelected}
@@ -106,16 +110,16 @@ describe('multiple variables', () => {
106110
/>
107111
);
108112

109-
variable.find('.variable-underline').simulate('click');
110-
variable.find('select').simulate('change', {
113+
fireEvent.click(container.querySelector('.variable-underline'));
114+
fireEvent.change(container.querySelector('select'), {
111115
target: {
112-
value: variable.find('select option').at(1).text(),
116+
value: container.querySelectorAll('select option')[1].text,
113117
},
114118
});
115119

116-
expect(called).toBe(true);
120+
expect(changeSelected).toHaveBeenCalledWith('project2');
117121

118-
expect(variable.state('showDropdown')).toBe(false);
122+
expect(container.querySelector('select')).not.toBeInTheDocument();
119123
});
120124

121125
it.todo('should render auth dropdown if default and oauth enabled');

jest.config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const path = require('path');
2-
31
module.exports = {
42
collectCoverageFrom: ['**/*.{js,jsx}', '!**/node_modules/**', '!jest.config.js', '!**/coverage/lcov-report/**'],
53
coveragePathIgnorePatterns: ['<rootDir>/webpack.*.js', 'dist/'],
@@ -17,7 +15,8 @@ module.exports = {
1715
},
1816

1917
rootDir: './',
20-
setupFiles: [path.join(__dirname, '/lib/enzyme')],
18+
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
19+
testEnvironment: 'jsdom',
2120
testMatch: ['**/__tests__/**/(*[._])+test.[jt]s?(x)'],
2221
testURL: 'http://localhost',
2322
transform: {

jest.setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom';

lib/enzyme.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)