Skip to content

Commit 7d66fbd

Browse files
authored
Merge pull request #215 from sparksuite/catch-up-to-speed
Update all packages + replace Enzyme with Testing Library
2 parents 284c3b0 + 55145f5 commit 7d66fbd

12 files changed

+8247
-5561
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ node_modules/
44
.DS_Store
55
yarn-debug.log*
66
yarn-error.log*
7+
.eslintcache

demo/package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
"homepage": ".",
55
"dependencies": {
66
"@testing-library/jest-dom": "^5.0.0",
7-
"@testing-library/react": "^10.0.0",
8-
"@testing-library/user-event": "^10.0.0",
9-
"@types/jest": "^25.1.0",
10-
"@types/node": "^13.1.0",
11-
"@types/react": "^16.9.0",
12-
"@types/react-dom": "^16.9.0",
7+
"@testing-library/react": "^11.2.2",
8+
"@testing-library/user-event": "^12.2.2",
9+
"@types/jest": "^26.0.15",
10+
"@types/node": "^14.0.0",
11+
"@types/react": "^17.0.0",
12+
"@types/react-dom": "^17.0.0",
1313
"prettier": "^2.0.2",
14-
"react": "^16.12.0",
14+
"react": "^17.0.1",
1515
"react-accessible-dropdown-menu-hook": "link:..",
16-
"react-dom": "^16.12.0",
17-
"react-scripts": "3.4.1",
18-
"typescript": "^3.8.3"
16+
"react-dom": "^17.0.1",
17+
"react-scripts": "4.0.1",
18+
"typescript": "^4.1.2"
1919
},
2020
"scripts": {
2121
"start": "react-scripts start",

demo/src/app.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ReactDOM from 'react-dom';
44
import App from './app';
55

66
// Tests
7-
it('renders', () => {
7+
it('Renders', () => {
88
const div = document.createElement('div');
99
ReactDOM.render(<App />, div);
1010
});

demo/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"resolveJsonModule": true,
1414
"isolatedModules": true,
1515
"noEmit": true,
16-
"jsx": "react"
16+
"jsx": "react-jsx",
17+
"noFallthroughCasesInSwitch": true
1718
},
1819
"include": ["src"]
1920
}

demo/yarn.lock

+4,384-3,733
Large diffs are not rendered by default.

package.json

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-accessible-dropdown-menu-hook",
3-
"version": "2.1.2",
3+
"version": "2.2.0",
44
"description": "A simple Hook for creating fully accessible dropdown menus in React",
55
"main": "dist/use-dropdown-menu.js",
66
"types": "dist/use-dropdown-menu.d.ts",
@@ -47,28 +47,27 @@
4747
"@babel/preset-env": "^7.7.6",
4848
"@babel/preset-react": "^7.7.4",
4949
"@babel/preset-typescript": "^7.7.4",
50-
"@types/enzyme": "^3.10.4",
51-
"@types/enzyme-adapter-react-16": "^1.0.5",
50+
"@testing-library/jest-dom": "^5.11.6",
51+
"@testing-library/react": "^11.2.2",
52+
"@testing-library/user-event": "^12.2.2",
5253
"@types/jest": "^26.0.3",
5354
"@types/jest-environment-puppeteer": "^4.3.1",
54-
"@types/react": "^16.9.16",
55-
"@typescript-eslint/eslint-plugin": "^2.11.0",
56-
"@typescript-eslint/parser": "^2.11.0",
55+
"@types/react": "^17.0.0",
56+
"@typescript-eslint/eslint-plugin": "^4.8.2",
57+
"@typescript-eslint/parser": "^4.8.2",
5758
"babel-jest": "link:./demo/node_modules/babel-jest",
58-
"enzyme": "^3.10.0",
59-
"enzyme-adapter-react-16": "^1.15.1",
60-
"eslint": "^6.7.2",
59+
"eslint": "^7.14.0",
6160
"eslint-config-prettier": "^6.7.0",
6261
"eslint-plugin-react": "^7.17.0",
6362
"eslint-plugin-react-hooks": "^4.0.0",
6463
"jest": "link:./demo/node_modules/jest",
6564
"jest-puppeteer": "^4.3.0",
6665
"prettier": "^2.0.2",
67-
"puppeteer": "^2.0.0",
66+
"puppeteer": "^5.5.0",
6867
"react": "link:./demo/node_modules/react",
6968
"react-dom": "link:./demo/node_modules/react-dom",
70-
"react-test-renderer": "^16.12.0",
71-
"typescript": "^4.0.2"
69+
"react-test-renderer": "^17.0.1",
70+
"typescript": "^4.1.2"
7271
},
7372
"jest": {
7473
"collectCoverage": true,
@@ -79,7 +78,7 @@
7978
"verbose": true,
8079
"projects": [
8180
{
82-
"displayName": "Enzyme",
81+
"displayName": "Testing Library",
8382
"setupFilesAfterEnv": [
8483
"<rootDir>/test/setupTests.ts"
8584
],

src/use-dropdown-menu.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface ButtonProps
1111
}
1212

1313
// A custom Hook that abstracts away the listeners/controls for dropdown menus
14+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1415
export default function useDropdownMenu(itemCount: number) {
1516
// Use state
1617
const [isOpen, setIsOpen] = useState<boolean>(false);
@@ -24,7 +25,7 @@ export default function useDropdownMenu(itemCount: number) {
2425

2526
// Initialize refs and update them when the item count changes
2627
useEffect(() => {
27-
itemRefs.current = [...Array(itemCount)].map(() => createRef<HTMLAnchorElement>());
28+
itemRefs.current = [...Array<undefined>(itemCount)].map(() => createRef<HTMLAnchorElement>());
2829
}, [itemCount]);
2930

3031
// Create type guard
@@ -187,7 +188,7 @@ export default function useDropdownMenu(itemCount: number) {
187188
'aria-expanded': isOpen,
188189
};
189190

190-
const itemProps = [...Array(itemCount)].map((ignore, index) => ({
191+
const itemProps = [...Array<undefined>(itemCount)].map((_ignore, index) => ({
191192
onKeyDown: itemListener,
192193
tabIndex: -1,
193194
role: 'menuitem',

test/puppeteer/demo.test.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ beforeEach(async () => {
2626
});
2727
});
2828

29-
it('has the correct page title', async () => {
29+
it('Has the correct page title', async () => {
3030
await expect(page.title()).resolves.toMatch('React Accessible Dropdown Menu Hook');
3131
});
3232

33-
it('leaves focus on the button after clicking it', async () => {
33+
it('Leaves focus on the button after clicking it', async () => {
3434
await page.click('#menu-button');
3535
await menuOpen();
3636

3737
expect(await currentFocusID()).toBe('menu-button');
3838
});
3939

40-
it('focuses on the menu button after pressing escape', async () => {
40+
it('Focuses on the menu button after pressing escape', async () => {
4141
await page.focus('#menu-button');
4242
await page.keyboard.down('Enter');
4343
await menuOpen();
@@ -48,7 +48,7 @@ it('focuses on the menu button after pressing escape', async () => {
4848
expect(await currentFocusID()).toBe('menu-button');
4949
});
5050

51-
it('disables scroll by arrow key when menu is open', async () => {
51+
it('Disables scroll by arrow key when menu is open', async () => {
5252
await page.setViewport({
5353
width: 1000,
5454
height: 500,
@@ -63,7 +63,7 @@ it('disables scroll by arrow key when menu is open', async () => {
6363
expect(await page.evaluate(() => window.scrollY)).toBe(currentScrollY);
6464
});
6565

66-
it('does not disable scroll by arrow key when menu is closed', async () => {
66+
it('Does not disable scroll by arrow key when menu is closed', async () => {
6767
await page.setViewport({
6868
width: 1000,
6969
height: 500,
@@ -75,7 +75,7 @@ it('does not disable scroll by arrow key when menu is closed', async () => {
7575
expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(currentScrollY);
7676
});
7777

78-
it('focuses on the next item in the tab order after pressing tab', async () => {
78+
it('Focuses on the next item in the tab order after pressing tab', async () => {
7979
await page.focus('#menu-button');
8080
await page.keyboard.down('Enter');
8181
await menuOpen();
@@ -86,7 +86,7 @@ it('focuses on the next item in the tab order after pressing tab', async () => {
8686
expect(await currentFocusID()).toBe('first-footer-link');
8787
});
8888

89-
it('focuses on the previous item in the tab order after pressing shift-tab', async () => {
89+
it('Focuses on the previous item in the tab order after pressing shift-tab', async () => {
9090
await page.focus('#menu-button');
9191
await page.keyboard.down('Enter');
9292
await menuOpen();
@@ -98,7 +98,7 @@ it('focuses on the previous item in the tab order after pressing shift-tab', asy
9898
expect(await currentFocusID()).toBe('menu-button');
9999
});
100100

101-
it('closes the menu if you click outside of it', async () => {
101+
it('Closes the menu if you click outside of it', async () => {
102102
await page.focus('#menu-button');
103103
await page.keyboard.down('Enter');
104104
await menuOpen();
@@ -109,7 +109,7 @@ it('closes the menu if you click outside of it', async () => {
109109
expect(true).toBe(true);
110110
});
111111

112-
it('leaves the menu open if you click inside of it', async () => {
112+
it('Leaves the menu open if you click inside of it', async () => {
113113
await page.focus('#menu-button');
114114
await page.keyboard.down('Enter');
115115
await menuOpen();
@@ -135,7 +135,7 @@ it('leaves the menu open if you click inside of it', async () => {
135135
expect(true).toBe(true);
136136
});
137137

138-
it('reroutes enter presses on menu items as clicks', async () => {
138+
it('Reroutes enter presses on menu items as clicks', async () => {
139139
let alertAppeared = false;
140140

141141
await page.focus('#menu-button');

test/setupTests.ts

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

test/test-component.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const TestComponent: React.FC = () => {
3737
Add Item
3838
</button>
3939

40-
<span id='is-open-indicator'>{isOpen ? 'true' : 'false'}</span>
40+
<span data-testid='is-open-indicator'>{isOpen ? 'true' : 'false'}</span>
4141
</React.Fragment>
4242
);
4343
};

0 commit comments

Comments
 (0)