wrapito 13.0.0-beta1 → 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -38
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +7 -86
- package/dist/index.mjs +7 -86
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -6,6 +6,21 @@ Wrap you tests so that you can test both behaviour and components with less effo
|
|
|
6
6
|
|
|
7
7
|
This version is agnostic and compatible with both [jest](https://jestjs.io/) and [vitest](https://vitest.dev/).
|
|
8
8
|
|
|
9
|
+
### Note:
|
|
10
|
+
|
|
11
|
+
From the version 13 wrapito is compatible with the new version of React and requires such versions of dependencies:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@testing-library/jest-dom": ">=5.16.4",
|
|
16
|
+
"@testing-library/react": ">=14.0.0",
|
|
17
|
+
"react-dom": ">=18.0.0",
|
|
18
|
+
"react": ">=18.0.0"
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
If your project uses React <=18.0.0, you can use wrapito <=12, but we extremely recommend to migrate to newest versions, because we are not maintaining legacy dependencies.
|
|
23
|
+
|
|
9
24
|
## 🎯 Motivation
|
|
10
25
|
|
|
11
26
|
As we are more focused on user interactions than implementation details. In order to test all the user interactions that
|
|
@@ -21,8 +36,6 @@ As we test our app we will be in two different scenarios where:
|
|
|
21
36
|
returns (renders) the expected result.
|
|
22
37
|
|
|
23
38
|
In general, if you want to test behaviour, you need to simulate external actions from user or from http responses.
|
|
24
|
-
Most of the existing testing libraries give you control of the user actions and thats why we just ask you to set in the
|
|
25
|
-
config what is the `render` function of your testing library.
|
|
26
39
|
Unfortunately, there aren't so many options when it comes to manage http requests and responses in the tests.
|
|
27
40
|
To give the mounted component context about which path is the current path where the app should be mounted, what props
|
|
28
41
|
does the component receive, what http requests will respond with which results or where should the portal be mounted we
|
|
@@ -46,40 +59,29 @@ const myWrappedComponent = wrap(MyComponent).mount()
|
|
|
46
59
|
|
|
47
60
|
## 👣 Initial setup
|
|
48
61
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
62
|
+
In the latest version of 🌯 `wrapito` passing the rendering/mounting function is optional, because we use `render` from `@testing-library/react` by default.
|
|
63
|
+
|
|
64
|
+
If one or more of your components use a `react portal` in any way, you will need to specify the `id` of the node where
|
|
65
|
+
it will be added.
|
|
66
|
+
|
|
67
|
+
To configure wrapito we recommend adding a setupTests.tsx file and adding there all your custom configs and extensions.
|
|
52
68
|
|
|
53
69
|
```js
|
|
54
|
-
import { render } from '@testing-library/react'
|
|
55
70
|
import { configure } from 'wrapito'
|
|
56
71
|
|
|
57
72
|
configure({
|
|
58
|
-
|
|
73
|
+
defaultHost: 'your-host-path',
|
|
74
|
+
portal: 'modal-root',
|
|
75
|
+
extend: {
|
|
76
|
+
/* Here you can group network calls to reuse them in your tests */
|
|
77
|
+
},
|
|
59
78
|
})
|
|
60
79
|
```
|
|
61
80
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
```js
|
|
65
|
-
"setupFiles"
|
|
66
|
-
:
|
|
67
|
-
[
|
|
68
|
-
"<rootDir>/config/jest/setup.wrapito.js"
|
|
69
|
-
],
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
If one or more of your components use a `react portal` in any way, you will need to specify the `id` of the node where
|
|
73
|
-
it will be added:
|
|
81
|
+
Add this line in your project setup (vite/cra):
|
|
74
82
|
|
|
75
83
|
```js
|
|
76
|
-
|
|
77
|
-
import { configure } from 'wrapito'
|
|
78
|
-
|
|
79
|
-
configure({
|
|
80
|
-
mount: render,
|
|
81
|
-
portal: 'modal-root',
|
|
82
|
-
})
|
|
84
|
+
setupFiles: ['./src/setupTests.tsx']
|
|
83
85
|
```
|
|
84
86
|
|
|
85
87
|
## 🏰 Builder API
|
|
@@ -92,8 +94,7 @@ given request, done by the production code, is not set up in the `responses obje
|
|
|
92
94
|
#### withNetwork
|
|
93
95
|
|
|
94
96
|
By using this feature you can configure the responses for your `http requests`. If your component is making a request
|
|
95
|
-
that is not set up in the `responses object`, it will not be validated and it will return an empty response with code
|
|
96
|
-
200.
|
|
97
|
+
that is not set up in the `responses object`, it will not be validated and it will return an empty response with code 200.
|
|
97
98
|
|
|
98
99
|
```js
|
|
99
100
|
import { wrap } from 'wrapito'
|
|
@@ -101,16 +102,14 @@ import { wrap } from 'wrapito'
|
|
|
101
102
|
const responses = {
|
|
102
103
|
host: 'my-host',
|
|
103
104
|
method: 'get',
|
|
104
|
-
path: '/path/to/get/a/single/product
|
|
105
|
+
path: '/path/to/get/a/single/product/',
|
|
105
106
|
responseBody: { id: 1, name: 'hummus' },
|
|
106
107
|
status: 200,
|
|
107
108
|
catchParams: true,
|
|
108
109
|
delay: 500,
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
wrap(MyComponent)
|
|
112
|
-
.withNetwork(responses)
|
|
113
|
-
.mount()
|
|
112
|
+
wrap(MyComponent).withNetwork(responses).mount()
|
|
114
113
|
```
|
|
115
114
|
|
|
116
115
|
You can specify the default `host` via configuration:
|
|
@@ -146,21 +145,19 @@ import { wrap } from 'wrapito'
|
|
|
146
145
|
|
|
147
146
|
const responses = [
|
|
148
147
|
{
|
|
149
|
-
path: '/path/to/get/the/products/list
|
|
148
|
+
path: '/path/to/get/the/products/list/',
|
|
150
149
|
responseBody: [
|
|
151
150
|
{ id: 1, name: 'hummus' },
|
|
152
151
|
{ id: 2, name: 'guacamole' },
|
|
153
|
-
]
|
|
152
|
+
],
|
|
154
153
|
},
|
|
155
154
|
{
|
|
156
|
-
path: '/path/to/get/a/single/product
|
|
155
|
+
path: '/path/to/get/a/single/product/',
|
|
157
156
|
responseBody: { id: 1, name: 'hummus' },
|
|
158
157
|
},
|
|
159
158
|
]
|
|
160
159
|
|
|
161
|
-
wrap(MyComponent)
|
|
162
|
-
.withNetwork(responses)
|
|
163
|
-
.mount()
|
|
160
|
+
wrap(MyComponent).withNetwork(responses).mount()
|
|
164
161
|
```
|
|
165
162
|
|
|
166
163
|
There might be cases where one request is called several times and we want it to return different responses. An example
|
|
@@ -322,6 +319,10 @@ git push origin v1.0.5
|
|
|
322
319
|
|
|
323
320
|
This will run a workflow in github that will publish this version for you.
|
|
324
321
|
|
|
322
|
+
### Release beta versions
|
|
323
|
+
|
|
324
|
+
WARNING: DO NOT MERGE YOUR PR IF YOU WANT TO DO A BETA RELEASE, SINCE THE CHANGES ARE NOT FULLY TRUSTED THEY SHOULD NOT GO TO MASTER
|
|
325
|
+
|
|
325
326
|
If you need to release beta versions to test things, you may do so with the -beta tag. E.g:
|
|
326
327
|
|
|
327
328
|
```
|
package/dist/index.d.cts
CHANGED
|
@@ -54,7 +54,7 @@ type Extensions = {
|
|
|
54
54
|
[key: string]: Extension;
|
|
55
55
|
};
|
|
56
56
|
type Component = React.ReactElement<any, any>;
|
|
57
|
-
type RenderResult = RenderResult$1
|
|
57
|
+
type RenderResult = RenderResult$1;
|
|
58
58
|
type Mount = (component: Component) => RenderResult;
|
|
59
59
|
interface Config {
|
|
60
60
|
defaultHost: string;
|
|
@@ -63,6 +63,7 @@ interface Config {
|
|
|
63
63
|
changeRoute: (path: string) => void;
|
|
64
64
|
history?: BrowserHistory;
|
|
65
65
|
portal?: string;
|
|
66
|
+
portals?: string[];
|
|
66
67
|
handleQueryParams?: boolean;
|
|
67
68
|
}
|
|
68
69
|
interface BrowserHistory extends History {
|
package/dist/index.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ type Extensions = {
|
|
|
54
54
|
[key: string]: Extension;
|
|
55
55
|
};
|
|
56
56
|
type Component = React.ReactElement<any, any>;
|
|
57
|
-
type RenderResult = RenderResult$1
|
|
57
|
+
type RenderResult = RenderResult$1;
|
|
58
58
|
type Mount = (component: Component) => RenderResult;
|
|
59
59
|
interface Config {
|
|
60
60
|
defaultHost: string;
|
|
@@ -63,6 +63,7 @@ interface Config {
|
|
|
63
63
|
changeRoute: (path: string) => void;
|
|
64
64
|
history?: BrowserHistory;
|
|
65
65
|
portal?: string;
|
|
66
|
+
portals?: string[];
|
|
66
67
|
handleQueryParams?: boolean;
|
|
67
68
|
}
|
|
68
69
|
interface BrowserHistory extends History {
|