Skip to content

Commit fe2136d

Browse files
authored
Testing: Remove unnecessary Enzyme React 16 workarounds (#14156)
* Testing: Bump `enzyme-adapter-react-16` to 1.10.0 * Testing: Avoid unforwarded Button mock No longer necessary with native support for forwardRef in Enzyme * Testing: Un-skip BlockControls snapshot test
1 parent 4472b1b commit fe2136d

File tree

21 files changed

+78
-94
lines changed

21 files changed

+78
-94
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/components/src/button/__mocks__/index.js

-17
This file was deleted.

packages/components/src/color-palette/test/__snapshots__/index.js.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,15 @@ exports[`ColorPalette should allow disabling custom color picker 1`] = `
180180
<div
181181
className="components-color-palette__custom-clear-wrapper"
182182
>
183-
<Button
183+
<ForwardRef(Button)
184184
className="components-color-palette__clear"
185185
isDefault={true}
186186
isSmall={true}
187187
onClick={[Function]}
188188
type="button"
189189
>
190190
Clear
191-
</Button>
191+
</ForwardRef(Button)>
192192
</div>
193193
</div>
194194
`;
@@ -272,15 +272,15 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
272272
renderContent={[Function]}
273273
renderToggle={[Function]}
274274
/>
275-
<Button
275+
<ForwardRef(Button)
276276
className="components-color-palette__clear"
277277
isDefault={true}
278278
isSmall={true}
279279
onClick={[Function]}
280280
type="button"
281281
>
282282
Clear
283-
</Button>
283+
</ForwardRef(Button)>
284284
</div>
285285
</div>
286286
`;

packages/components/src/color-palette/test/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { shallow } from 'enzyme';
88
*/
99
import ColorPalette from '../';
1010

11-
jest.mock( '../../button' );
12-
1311
describe( 'ColorPalette', () => {
1412
const colors = [ { name: 'red', color: '#f00' }, { name: 'white', color: '#fff' }, { name: 'blue', color: '#00f' } ];
1513
const currentColor = '#f00';

packages/components/src/icon-button/test/index.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { shallow } from 'enzyme';
88
*/
99
import IconButton from '../';
1010

11-
jest.mock( '../../button' );
12-
1311
describe( 'IconButton', () => {
1412
describe( 'basic rendering', () => {
1513
it( 'should render an top level element with only a class property', () => {
@@ -30,15 +28,15 @@ describe( 'IconButton', () => {
3028

3129
it( 'should add an aria-label when the label property is used', () => {
3230
const iconButton = shallow( <IconButton label="WordPress">WordPress</IconButton> );
33-
expect( iconButton.name() ).toBe( 'Button' );
31+
expect( iconButton.name() ).toBe( 'ForwardRef(Button)' );
3432
expect( iconButton.prop( 'aria-label' ) ).toBe( 'WordPress' );
3533
} );
3634

3735
it( 'should add an aria-label when the label property is used, with Tooltip wrapper', () => {
3836
const iconButton = shallow( <IconButton label="WordPress" /> );
3937
expect( iconButton.name() ).toBe( 'Tooltip' );
4038
expect( iconButton.prop( 'text' ) ).toBe( 'WordPress' );
41-
expect( iconButton.find( 'Button' ).prop( 'aria-label' ) ).toBe( 'WordPress' );
39+
expect( iconButton.find( 'ForwardRef(Button)' ).prop( 'aria-label' ) ).toBe( 'WordPress' );
4240
} );
4341

4442
it( 'should support explicit aria-label override', () => {
@@ -60,12 +58,12 @@ describe( 'IconButton', () => {
6058
const iconButton = shallow( <IconButton label="WordPress" tooltip="Custom" /> );
6159
expect( iconButton.name() ).toBe( 'Tooltip' );
6260
expect( iconButton.prop( 'text' ) ).toBe( 'Custom' );
63-
expect( iconButton.find( 'Button' ).prop( 'aria-label' ) ).toBe( 'WordPress' );
61+
expect( iconButton.find( 'ForwardRef(Button)' ).prop( 'aria-label' ) ).toBe( 'WordPress' );
6462
} );
6563

6664
it( 'should allow tooltip disable', () => {
6765
const iconButton = shallow( <IconButton label="WordPress" tooltip={ false } /> );
68-
expect( iconButton.name() ).toBe( 'Button' );
66+
expect( iconButton.name() ).toBe( 'ForwardRef(Button)' );
6967
expect( iconButton.prop( 'aria-label' ) ).toBe( 'WordPress' );
7068
} );
7169

packages/components/src/menu-item/test/__snapshots__/index.js.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ exports[`MenuItem should match snapshot when all props provided 1`] = `
1717
`;
1818

1919
exports[`MenuItem should match snapshot when info is provided 1`] = `
20-
<Button
20+
<ForwardRef(Button)
2121
aria-describedby="edit-post-feature-toggle__info-1"
2222
className="components-menu-item__button"
2323
role="menuitem"
@@ -36,7 +36,7 @@ exports[`MenuItem should match snapshot when info is provided 1`] = `
3636
<Shortcut
3737
className="components-menu-item__shortcut"
3838
/>
39-
</Button>
39+
</ForwardRef(Button)>
4040
`;
4141

4242
exports[`MenuItem should match snapshot when isSelected and role are optionally provided 1`] = `
@@ -55,13 +55,13 @@ exports[`MenuItem should match snapshot when isSelected and role are optionally
5555
`;
5656

5757
exports[`MenuItem should match snapshot when only label provided 1`] = `
58-
<Button
58+
<ForwardRef(Button)
5959
className="components-menu-item__button"
6060
role="menuitem"
6161
>
6262
My item
6363
<Shortcut
6464
className="components-menu-item__shortcut"
6565
/>
66-
</Button>
66+
</ForwardRef(Button)>
6767
`;

packages/components/src/menu-item/test/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { noop } from 'lodash';
99
*/
1010
import { MenuItem } from '../';
1111

12-
jest.mock( '../../button' );
13-
1412
describe( 'MenuItem', () => {
1513
it( 'should match snapshot when only label provided', () => {
1614
const wrapper = shallow(

packages/components/src/panel/test/body.js

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { shallow, mount } from 'enzyme';
88
*/
99
import { PanelBody } from '../body';
1010

11-
jest.mock( '../../button' );
12-
1311
describe( 'PanelBody', () => {
1412
describe( 'basic rendering', () => {
1513
it( 'should render an empty div with the matching className', () => {

packages/edit-post/src/components/header/more-menu/test/__snapshots__/index.js.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ exports[`MoreMenu should match snapshot 1`] = `
2323
position="bottom"
2424
text="Show more tools & options"
2525
>
26-
<Button
26+
<ForwardRef(Button)
2727
aria-expanded={false}
2828
aria-label="Show more tools & options"
2929
className="components-icon-button"
@@ -79,7 +79,7 @@ exports[`MoreMenu should match snapshot 1`] = `
7979
</SVG>
8080
</Dashicon>
8181
</button>
82-
</Button>
82+
</ForwardRef(Button)>
8383
</Tooltip>
8484
</IconButton>
8585
</div>

packages/edit-post/src/components/header/more-menu/test/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { mount } from 'enzyme';
88
*/
99
import MoreMenu from '../index';
1010

11-
jest.mock( '../../../../../../components/src/button' );
12-
1311
describe( 'MoreMenu', () => {
1412
it( 'should match snapshot', () => {
1513
const wrapper = mount(

packages/edit-post/src/components/sidebar/plugin-post-publish-panel/test/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { render } from '@wordpress/element';
99
*/
1010
import PluginPostPublishPanel from '../';
1111

12-
jest.mock( '../../../../../../components/src/button' );
13-
1412
describe( 'PluginPostPublishPanel', () => {
1513
test( 'renders fill properly', () => {
1614
const div = document.createElement( 'div' );

packages/edit-post/src/components/sidebar/plugin-pre-publish-panel/test/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { render } from '@wordpress/element';
99
*/
1010
import PluginPrePublishPanel from '../';
1111

12-
jest.mock( '../../../../../../components/src/button' );
13-
1412
describe( 'PluginPrePublishPanel', () => {
1513
test( 'renders fill properly', () => {
1614
const div = document.createElement( 'div' );
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,45 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`BlockControls Should render a dynamic toolbar of controls 1`] = `
4-
<Fill
5-
name="Block.Toolbar"
6-
>
7-
<Toolbar
8-
controls={
9-
Array [
10-
Object {
11-
"align": "left",
12-
"icon": "editor-alignleft",
13-
"title": "Align left",
14-
},
15-
Object {
16-
"align": "center",
17-
"icon": "editor-aligncenter",
18-
"title": "Align center",
19-
},
20-
Object {
21-
"align": "right",
22-
"icon": "editor-alignright",
23-
"title": "Align right",
24-
},
25-
]
3+
exports[`BlockControls should render a dynamic toolbar of controls 1`] = `
4+
<ContextProvider
5+
value={
6+
Object {
7+
"clientId": undefined,
8+
"focusedElement": null,
9+
"isSelected": true,
10+
"name": undefined,
11+
"setFocusedElement": [Function],
2612
}
27-
/>
28-
<p>
29-
Child
30-
</p>
31-
</Fill>
13+
}
14+
>
15+
<WithFilters(Edit)
16+
isSelected={true}
17+
>
18+
<IfBlockEditSelected(BlockControlsFill)
19+
controls={
20+
Array [
21+
Object {
22+
"align": "left",
23+
"icon": "editor-alignleft",
24+
"title": "Align left",
25+
},
26+
Object {
27+
"align": "center",
28+
"icon": "editor-aligncenter",
29+
"title": "Align center",
30+
},
31+
Object {
32+
"align": "right",
33+
"icon": "editor-alignright",
34+
"title": "Align right",
35+
},
36+
]
37+
}
38+
>
39+
<p>
40+
Child
41+
</p>
42+
</IfBlockEditSelected(BlockControlsFill)>
43+
</WithFilters(Edit)>
44+
</ContextProvider>
3245
`;

packages/editor/src/components/block-controls/test/index.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { shallow } from 'enzyme';
66
/**
77
* Internal dependencies
88
*/
9-
import { BlockControls } from '../';
9+
import BlockControls from '../';
10+
import BlockEdit from '../../block-edit';
1011

1112
describe( 'BlockControls', () => {
1213
const controls = [
@@ -27,9 +28,15 @@ describe( 'BlockControls', () => {
2728
},
2829
];
2930

30-
// Skipped temporarily until Enzyme publishes new version that works with React 16.3.0 APIs.
31-
// eslint-disable-next-line jest/no-disabled-tests
32-
test.skip( 'Should render a dynamic toolbar of controls', () => {
33-
expect( shallow( <BlockControls controls={ controls } children={ <p>Child</p> } /> ) ).toMatchSnapshot();
31+
it( 'should render a dynamic toolbar of controls', () => {
32+
const wrapper = shallow(
33+
<BlockEdit isSelected>
34+
<BlockControls controls={ controls }>
35+
<p>Child</p>
36+
</BlockControls>
37+
</BlockEdit>
38+
);
39+
40+
expect( wrapper ).toMatchSnapshot();
3441
} );
3542
} );

packages/editor/src/components/post-preview-button/test/__snapshots__/index.js.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`PostPreviewButton render() should render currentPostLink otherwise 1`] = `
4-
<Button
4+
<ForwardRef(Button)
55
className="editor-post-preview"
66
disabled={false}
77
href="https://wordpress.org/?p=1"
@@ -20,11 +20,11 @@ exports[`PostPreviewButton render() should render currentPostLink otherwise 1`]
2020
>
2121
Click “Preview” to load a preview of this page, so you can make sure you’re happy with your blocks.
2222
</WithSelect(WithDispatch(DotTip))>
23-
</Button>
23+
</ForwardRef(Button)>
2424
`;
2525

2626
exports[`PostPreviewButton render() should render previewLink if provided 1`] = `
27-
<Button
27+
<ForwardRef(Button)
2828
className="editor-post-preview"
2929
disabled={false}
3030
href="https://wordpress.org/?p=1&preview=true"
@@ -43,5 +43,5 @@ exports[`PostPreviewButton render() should render previewLink if provided 1`] =
4343
>
4444
Click “Preview” to load a preview of this page, so you can make sure you’re happy with your blocks.
4545
</WithSelect(WithDispatch(DotTip))>
46-
</Button>
46+
</ForwardRef(Button)>
4747
`;

packages/editor/src/components/post-preview-button/test/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { shallow } from 'enzyme';
88
*/
99
import { PostPreviewButton } from '../';
1010

11-
jest.mock( '../../../../../components/src/button' );
12-
1311
describe( 'PostPreviewButton', () => {
1412
describe( 'setPreviewWindowLink()', () => {
1513
it( 'should do nothing if there is no preview window', () => {

packages/editor/src/components/post-publish-button/test/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { shallow } from 'enzyme';
88
*/
99
import { PostPublishButton } from '../';
1010

11-
jest.mock( '../../../../../components/src/button' );
12-
1311
describe( 'PostPublishButton', () => {
1412
describe( 'aria-disabled', () => {
1513
it( 'should be true if post is currently saving', () => {
@@ -196,6 +194,6 @@ describe( 'PostPublishButton', () => {
196194
/>
197195
);
198196

199-
expect( wrapper.find( 'Button' ).prop( 'isBusy' ) ).toBe( true );
197+
expect( wrapper.find( 'ForwardRef(Button)' ).prop( 'isBusy' ) ).toBe( true );
200198
} );
201199
} );

packages/jest-preset-default/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
### Internal
99

1010
- The bundled `enzyme` dependency has been updated from requiring `^3.7.0` to requiring `^3.9.0` ([#13922](https://github.com/WordPress/gutenberg/pull/13922)).
11+
- The bundled `enzyme-adapter-react-16` dependency has been updated from requiring `^1.6.0` to requiring `^1.10.0` ([#13922](https://github.com/WordPress/gutenberg/pull/13922)).
1112

1213
## 3.0.3 (2018-11-20)
1314

packages/jest-preset-default/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@wordpress/jest-console": "file:../jest-console",
3434
"babel-jest": "^24.1.0",
3535
"enzyme": "^3.9.0",
36-
"enzyme-adapter-react-16": "^1.9.1",
36+
"enzyme-adapter-react-16": "^1.10.0",
3737
"enzyme-to-json": "^3.3.5"
3838
},
3939
"peerDependencies": {

0 commit comments

Comments
 (0)