@tramvai/test-react 1.45.0 → 1.46.8
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 +18 -18
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# Tramvai test React
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Set of helpers for testing React-components
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Helpers are based on libraries [@testing-library/react](https://github.com/testing-library/react-testing-library) [@testing-library/react-hooks](https://github.com/testing-library/react-hooks-testing-library)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
If you are using jest for testing, consider to add a library [@testing-library/jest-dom](https://github.com/testing-library/jest-dom)
|
|
8
8
|
|
|
9
|
-
>
|
|
9
|
+
> `react` should be installed manually
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Installation
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
npm i --save-dev @tramvai/test-react
|
|
@@ -16,9 +16,9 @@ npm i --save-dev @tramvai/test-react
|
|
|
16
16
|
|
|
17
17
|
## How to
|
|
18
18
|
|
|
19
|
-
###
|
|
19
|
+
### Test component
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Under the hood the [@testing-library/react](https://testing-library.com/docs/react-testing-library/intro) is used.
|
|
22
22
|
|
|
23
23
|
```ts
|
|
24
24
|
/**
|
|
@@ -30,19 +30,19 @@ describe('test', () => {
|
|
|
30
30
|
it('render', async () => {
|
|
31
31
|
const { render, rerender, context, act, fireEvent, Wrapper } = testComponent(<Cmp id={1} />);
|
|
32
32
|
|
|
33
|
-
//
|
|
33
|
+
// test component render
|
|
34
34
|
expect(render.getByTestId('test').textContent).toBe('Content 1');
|
|
35
35
|
|
|
36
|
-
//
|
|
36
|
+
// test render after store update
|
|
37
37
|
act(() => {
|
|
38
38
|
context.dispatch(event('data'));
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
//
|
|
41
|
+
// interact with the component
|
|
42
42
|
fireEvent.click(render.getByText('Button'));
|
|
43
43
|
|
|
44
|
-
//
|
|
45
|
-
rerender(<Cmp id={2} />)
|
|
44
|
+
// component rerender
|
|
45
|
+
rerender(<Cmp id={2} />);
|
|
46
46
|
|
|
47
47
|
expect(render.getByTestId('test').textContent).toBe('Content 2');
|
|
48
48
|
});
|
|
@@ -51,16 +51,16 @@ describe('test', () => {
|
|
|
51
51
|
|
|
52
52
|
<p>
|
|
53
53
|
<details>
|
|
54
|
-
<summary
|
|
54
|
+
<summary>More examples</summary>
|
|
55
55
|
|
|
56
56
|
@inline src/testComponent.spec.tsx
|
|
57
57
|
|
|
58
58
|
</details>
|
|
59
59
|
</p>
|
|
60
60
|
|
|
61
|
-
###
|
|
61
|
+
### Test React-hooks
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
Under the hood the [@testing-library/react-hooks](https://github.com/testing-library/react-hooks-testing-library) is used.
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
66
|
/**
|
|
@@ -72,10 +72,10 @@ describe('test', () => {
|
|
|
72
72
|
it('hook', async () => {
|
|
73
73
|
const { result, context, act } = testHook(() => useHook());
|
|
74
74
|
|
|
75
|
-
//
|
|
75
|
+
// test the result of hook call
|
|
76
76
|
expect(result.current).toBe('result');
|
|
77
77
|
|
|
78
|
-
//
|
|
78
|
+
// test the result after store update
|
|
79
79
|
act(() => {
|
|
80
80
|
context.dispatch(event('data'));
|
|
81
81
|
});
|
|
@@ -85,7 +85,7 @@ describe('test', () => {
|
|
|
85
85
|
|
|
86
86
|
<p>
|
|
87
87
|
<details>
|
|
88
|
-
<summary
|
|
88
|
+
<summary>More examples</summary>
|
|
89
89
|
|
|
90
90
|
@inline src/testHook.spec.tsx
|
|
91
91
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/test-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.46.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"@testing-library/react": "^11.2.6",
|
|
22
22
|
"@testing-library/react-hooks": "^5.1.2",
|
|
23
23
|
"@tinkoff/router": "0.1.64",
|
|
24
|
-
"@tramvai/react": "1.
|
|
25
|
-
"@tramvai/state": "1.
|
|
26
|
-
"@tramvai/test-mocks": "1.
|
|
27
|
-
"@tramvai/tokens-common": "1.
|
|
24
|
+
"@tramvai/react": "1.46.8",
|
|
25
|
+
"@tramvai/state": "1.46.8",
|
|
26
|
+
"@tramvai/test-mocks": "1.46.8",
|
|
27
|
+
"@tramvai/tokens-common": "1.46.8",
|
|
28
28
|
"react-test-renderer": "^17.0.2",
|
|
29
29
|
"tslib": "^2.0.3"
|
|
30
30
|
},
|