Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create @wordpress/test-utils package #18855

Closed
wants to merge 14 commits into from
Closed
1 change: 1 addition & 0 deletions bin/api-docs/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const packages = [
'redux-routine',
'rich-text',
'shortcode',
'test-utils',
'url',
'viewport',
'warning',
Expand Down
6 changes: 6 additions & 0 deletions docs/manifest-devhub.json
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,12 @@
"markdown_source": "../packages/shortcode/README.md",
"parent": "packages"
},
{
"title": "@wordpress/test-utils",
"slug": "packages-test-utils",
"markdown_source": "../packages/test-utils/README.md",
"parent": "packages"
},
{
"title": "@wordpress/token-list",
"slug": "packages-token-list",
Expand Down
166 changes: 166 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"@wordpress/npm-package-json-lint-config": "file:packages/npm-package-json-lint-config",
"@wordpress/postcss-themes": "file:packages/postcss-themes",
"@wordpress/scripts": "file:packages/scripts",
"@wordpress/test-utils": "file:packages/test-utils",
"babel-loader": "8.0.6",
"babel-plugin-emotion": "10.0.27",
"babel-plugin-inline-json-import": "0.3.2",
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-preset-default/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Master

### New Features

- Add `@wordpress/test-utils/extend-expect` to Jest setup ([18855](https://github.com/WordPress/gutenberg/pull/18855)).

## 5.4.0 (2020-02-04)

### Bug Fixes
Expand Down
1 change: 1 addition & 0 deletions packages/jest-preset-default/jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
require.resolve(
'@wordpress/jest-preset-default/scripts/setup-test-framework.js'
),
require.resolve( '@wordpress/test-utils/extend-expect' ),
],
snapshotSerializers: [ require.resolve( 'enzyme-to-json/serializer.js' ) ],
testMatch: [
Expand Down
1 change: 1 addition & 0 deletions packages/jest-preset-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"dependencies": {
"@jest/reporters": "^24.8.0",
"@wordpress/jest-console": "file:../jest-console",
"@wordpress/test-utils": "file:../test-utils",
"babel-jest": "^24.9.0",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.10.0",
Expand Down
1 change: 1 addition & 0 deletions packages/test-utils/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
1 change: 1 addition & 0 deletions packages/test-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## master
112 changes: 112 additions & 0 deletions packages/test-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Test Utils

Integration test utils for WordPress.

## Installation

Install the module

```bash
npm install @wordpress/test-utils --save-dev
```

## API

<!-- START TOKEN(Autogenerated API docs) -->

<a name="act" href="#act">#</a> **act**

Simply calls ReactDOMTestUtils.act(cb) If that's not available (older version of react)
then it simply calls the given callback immediately.

_Related_

- <https://testing-library.com/docs/react-testing-library/api#act>
- <https://reactjs.org/docs/test-utils.html#act>

<a name="blur" href="#blur">#</a> **blur**

Blur element.

_Parameters_

- _element_ `[Element]`:

<a name="click" href="#click">#</a> **click**

Click element.

_Parameters_

- _element_ `Element`:
- _options_ `[Object]`:

<a name="fireEvent" href="#fireEvent">#</a> **fireEvent**

Convenience methods for firing DOM events.

_Related_

- <https://testing-library.com/docs/dom-testing-library/api-events>

<a name="focus" href="#focus">#</a> **focus**

Focus element.

_Parameters_

- _element_ `Element`:

<a name="hover" href="#hover">#</a> **hover**

Hover element.

_Parameters_

- _element_ `Element`:
- _options_ `[Object]`:

<a name="press" href="#press">#</a> **press**

Press element.

_Parameters_

- _key_ `string`:
- _element_ `[Element]`:
- _options_ `[Object]`:

<a name="render" href="#render">#</a> **render**

Render into a container which is appended to `document.body`.

_Related_

- <https://testing-library.com/docs/react-testing-library/api#render>

<a name="type" href="#type">#</a> **type**

Type on a text field element.

_Parameters_

- _text_ `string`:
- _element_ `[Element]`:
- _options_ `[Object]`:

<a name="wait" href="#wait">#</a> **wait**

When in need to wait for non-deterministic periods of time you can use `wait`
to wait for your expectations to pass. The `wait` function is a small
wrapper around the [`wait-for-expect`](https://github.com/TheBrainFamily/wait-for-expect)
module.

_Related_

- <https://testing-library.com/docs/dom-testing-library/api-async#wait>
- <https://github.com/TheBrainFamily/wait-for-expect>


<!-- END TOKEN(Autogenerated API docs) -->

<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
4 changes: 4 additions & 0 deletions packages/test-utils/extend-expect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* External dependencies
*/
require( '@testing-library/jest-dom/extend-expect' );
Loading