Skip to content

Commit

Permalink
Fix some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Mar 30, 2022
1 parent 3b03136 commit 32f8fd5
Show file tree
Hide file tree
Showing 17 changed files with 378 additions and 566 deletions.
132 changes: 31 additions & 101 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"@storybook/manager-webpack5": "6.4.9",
"@storybook/react": "6.4.9",
"@testing-library/jest-dom": "5.16.1",
"@testing-library/react": "11.2.2",
"@testing-library/react": "13.0.0-alpha.6",
"@testing-library/react-native": "9.0.0",
"@testing-library/user-event": "^14.0.0-beta.13",
"@types/classnames": "2.3.1",
Expand Down
20 changes: 0 additions & 20 deletions packages/block-editor/src/components/url-input/test/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* External dependencies
*/
import { shallow } from 'enzyme';
import TestUtils from 'react-dom/test-utils';
import ReactDOM from 'react-dom';

/**
* Internal dependencies
Expand Down Expand Up @@ -70,22 +68,4 @@ describe( 'URLInputButton', () => {
wrapper.find( '.block-editor-url-input__back' ).simulate( 'click' );
expect( wrapper.state().expanded ).toBe( false );
} );
it( 'should close the form when user submits it', () => {
const wrapper = TestUtils.renderIntoDocument( <URLInputButton /> );
const buttonElement = () =>
TestUtils.scryRenderedDOMComponentsWithClass(
wrapper,
'components-toolbar__control'
);
const formElement = () =>
TestUtils.scryRenderedDOMComponentsWithTag( wrapper, 'form' );
TestUtils.Simulate.click( buttonElement().shift() );
expect( wrapper.state.expanded ).toBe( true );
TestUtils.Simulate.submit( formElement().shift() );
expect( wrapper.state.expanded ).toBe( false );
ReactDOM.unmountComponentAtNode(
// eslint-disable-next-line react/no-find-dom-node
ReactDOM.findDOMNode( wrapper ).parentNode
);
} );
} );
10 changes: 5 additions & 5 deletions packages/components/src/button/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
* External dependencies
*/
import { shallow } from 'enzyme';
import TestUtils from 'react-dom/test-utils';
/**
* WordPress dependencies
*/
import { createRef } from '@wordpress/element';
import { createRef, createRoot } from '@wordpress/element';
import { plusCircle } from '@wordpress/icons';

/**
Expand Down Expand Up @@ -245,10 +244,11 @@ describe( 'Button', () => {
describe( 'ref forwarding', () => {
it( 'should enable access to DOM element', () => {
const ref = createRef();
const container = document.createElement( 'div' );
const root = createRoot( container );
root.render( <ButtonWithForwardedRef ref={ ref } /> );
jest.runAllTimers();

TestUtils.renderIntoDocument(
<ButtonWithForwardedRef ref={ ref } />
);
expect( ref.current.type ).toBe( 'button' );
} );
} );
Expand Down
Loading

0 comments on commit 32f8fd5

Please sign in to comment.