@tramvai/test-react 2.28.0 → 2.29.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 +4 -4
- package/lib/index.es.js +4 -3
- package/lib/index.js +3 -2
- package/lib/testComponent.d.ts +2 -1
- package/lib/testHook.d.ts +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -42,10 +42,10 @@ import { testComponent } from '@tramvai/test-react';
|
|
|
42
42
|
|
|
43
43
|
describe('test', () => {
|
|
44
44
|
it('render', async () => {
|
|
45
|
-
const {
|
|
45
|
+
const { screen, rerender, context, act, fireEvent, Wrapper } = testComponent(<Cmp id={1} />);
|
|
46
46
|
|
|
47
47
|
// test component render
|
|
48
|
-
expect(
|
|
48
|
+
expect(screen.getByTestId('test').textContent).toBe('Content 1');
|
|
49
49
|
|
|
50
50
|
// test render after store update
|
|
51
51
|
act(() => {
|
|
@@ -53,12 +53,12 @@ describe('test', () => {
|
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
// interact with the component
|
|
56
|
-
fireEvent.click(
|
|
56
|
+
fireEvent.click(screen.getByText('Button'));
|
|
57
57
|
|
|
58
58
|
// component rerender
|
|
59
59
|
rerender(<Cmp id={2} />);
|
|
60
60
|
|
|
61
|
-
expect(
|
|
61
|
+
expect(screen.getByTestId('test').textContent).toBe('Content 2');
|
|
62
62
|
});
|
|
63
63
|
});
|
|
64
64
|
```
|
package/lib/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { render, act, fireEvent, renderHook } from '@testing-library/react';
|
|
1
|
+
import { render, act, screen, fireEvent, renderHook } from '@testing-library/react';
|
|
2
2
|
export * from '@testing-library/react';
|
|
3
3
|
import { jsx } from 'react/jsx-runtime';
|
|
4
4
|
import { Provider } from '@tramvai/state';
|
|
@@ -7,7 +7,7 @@ import { Provider as Provider$1 } from '@tinkoff/router';
|
|
|
7
7
|
import { createMockContext, createMockRouter } from '@tramvai/test-mocks';
|
|
8
8
|
import { waitRaf } from '@tramvai/test-jsdom';
|
|
9
9
|
|
|
10
|
-
const testComponent = (element, { providers, initialState, store, stores, di, context = createMockContext({ initialState, providers, di, store, stores }), currentRoute, currentUrl, router = createMockRouter({ currentRoute, currentUrl }), renderOptions, } = {}) => {
|
|
10
|
+
const testComponent = (element, { providers, modules, initialState, store, stores, di, context = createMockContext({ initialState, providers, modules, di, store, stores }), currentRoute, currentUrl, router = createMockRouter({ currentRoute, currentUrl }), renderOptions, } = {}) => {
|
|
11
11
|
const Wrapper = ({ children }) => (jsx(Provider, { context: context, serverState: initialState, children: jsx(DIContext.Provider, { value: context.di, children: jsx(Provider$1, { router: router, serverState: initialState === null || initialState === void 0 ? void 0 : initialState.router, children: children }) }) }));
|
|
12
12
|
const renderResults = render(jsx(Wrapper, { children: element }), renderOptions);
|
|
13
13
|
return {
|
|
@@ -23,13 +23,14 @@ const testComponent = (element, { providers, initialState, store, stores, di, co
|
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
25
|
},
|
|
26
|
+
screen,
|
|
26
27
|
fireEvent,
|
|
27
28
|
context,
|
|
28
29
|
router,
|
|
29
30
|
};
|
|
30
31
|
};
|
|
31
32
|
|
|
32
|
-
const testHook = (hookCallback, { providers, initialState, store, stores, di, context = createMockContext({ initialState, providers, di, store, stores }), currentRoute, currentUrl, router = createMockRouter({ currentRoute, currentUrl }), renderOptions, } = {}) => {
|
|
33
|
+
const testHook = (hookCallback, { providers, modules, initialState, store, stores, di, context = createMockContext({ initialState, providers, modules, di, store, stores }), currentRoute, currentUrl, router = createMockRouter({ currentRoute, currentUrl }), renderOptions, } = {}) => {
|
|
33
34
|
var _a;
|
|
34
35
|
const Wrapper = (_a = renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions.wrapper) !== null && _a !== void 0 ? _a : (({ children }) => children);
|
|
35
36
|
const { result, rerender } = renderHook(hookCallback, {
|
package/lib/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var router = require('@tinkoff/router');
|
|
|
10
10
|
var testMocks = require('@tramvai/test-mocks');
|
|
11
11
|
var testJsdom = require('@tramvai/test-jsdom');
|
|
12
12
|
|
|
13
|
-
const testComponent = (element, { providers, initialState, store, stores, di, context = testMocks.createMockContext({ initialState, providers, di, store, stores }), currentRoute, currentUrl, router: router$1 = testMocks.createMockRouter({ currentRoute, currentUrl }), renderOptions, } = {}) => {
|
|
13
|
+
const testComponent = (element, { providers, modules, initialState, store, stores, di, context = testMocks.createMockContext({ initialState, providers, modules, di, store, stores }), currentRoute, currentUrl, router: router$1 = testMocks.createMockRouter({ currentRoute, currentUrl }), renderOptions, } = {}) => {
|
|
14
14
|
const Wrapper = ({ children }) => (jsxRuntime.jsx(state.Provider, { context: context, serverState: initialState, children: jsxRuntime.jsx(react$1.DIContext.Provider, { value: context.di, children: jsxRuntime.jsx(router.Provider, { router: router$1, serverState: initialState === null || initialState === void 0 ? void 0 : initialState.router, children: children }) }) }));
|
|
15
15
|
const renderResults = react.render(jsxRuntime.jsx(Wrapper, { children: element }), renderOptions);
|
|
16
16
|
return {
|
|
@@ -26,13 +26,14 @@ const testComponent = (element, { providers, initialState, store, stores, di, co
|
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
28
|
},
|
|
29
|
+
screen: react.screen,
|
|
29
30
|
fireEvent: react.fireEvent,
|
|
30
31
|
context,
|
|
31
32
|
router: router$1,
|
|
32
33
|
};
|
|
33
34
|
};
|
|
34
35
|
|
|
35
|
-
const testHook = (hookCallback, { providers, initialState, store, stores, di, context = testMocks.createMockContext({ initialState, providers, di, store, stores }), currentRoute, currentUrl, router: router$1 = testMocks.createMockRouter({ currentRoute, currentUrl }), renderOptions, } = {}) => {
|
|
36
|
+
const testHook = (hookCallback, { providers, modules, initialState, store, stores, di, context = testMocks.createMockContext({ initialState, providers, modules, di, store, stores }), currentRoute, currentUrl, router: router$1 = testMocks.createMockRouter({ currentRoute, currentUrl }), renderOptions, } = {}) => {
|
|
36
37
|
var _a;
|
|
37
38
|
const Wrapper = (_a = renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions.wrapper) !== null && _a !== void 0 ? _a : (({ children }) => children);
|
|
38
39
|
const { result, rerender } = react.renderHook(hookCallback, {
|
package/lib/testComponent.d.ts
CHANGED
|
@@ -12,10 +12,11 @@ declare type Options = OptionsDi & OptionsContext & OptionsRouter & {
|
|
|
12
12
|
router?: AbstractRouter;
|
|
13
13
|
renderOptions?: RenderOptions;
|
|
14
14
|
};
|
|
15
|
-
export declare const testComponent: (element: React.ReactElement, { providers, initialState, store, stores, di, context, currentRoute, currentUrl, router, renderOptions, }?: Options) => {
|
|
15
|
+
export declare const testComponent: (element: React.ReactElement, { providers, modules, initialState, store, stores, di, context, currentRoute, currentUrl, router, renderOptions, }?: Options) => {
|
|
16
16
|
render: import("@testing-library/react").RenderResult<typeof import("@testing-library/dom/types/queries"), HTMLElement, HTMLElement>;
|
|
17
17
|
rerender: (el: React.ReactElement) => void;
|
|
18
18
|
act: (callback: () => Promise<void> | void) => Promise<undefined>;
|
|
19
|
+
screen: import("@testing-library/react").Screen<typeof import("@testing-library/dom/types/queries")>;
|
|
19
20
|
fireEvent: import("@testing-library/react").FireFunction & import("@testing-library/react").FireObject;
|
|
20
21
|
context: import("@tinkoff/dippy").BaseTokenInterface<import("@tramvai/tokens-common").ConsumerContext>;
|
|
21
22
|
router: AbstractRouter;
|
package/lib/testHook.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ declare type Options = OptionsDi & OptionsContext & OptionsRouter & {
|
|
|
11
11
|
router?: AbstractRouter;
|
|
12
12
|
renderOptions?: RenderHookOptions<any>;
|
|
13
13
|
};
|
|
14
|
-
export declare const testHook: <TProps, TResult>(hookCallback: (props: TProps) => TResult, { providers, initialState, store, stores, di, context, currentRoute, currentUrl, router, renderOptions, }?: Options) => {
|
|
14
|
+
export declare const testHook: <TProps, TResult>(hookCallback: (props: TProps) => TResult, { providers, modules, initialState, store, stores, di, context, currentRoute, currentUrl, router, renderOptions, }?: Options) => {
|
|
15
15
|
result: {
|
|
16
16
|
current: TResult;
|
|
17
17
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/test-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.29.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@testing-library/react": "^13.3.0",
|
|
22
22
|
"@tinkoff/router": "0.2.3",
|
|
23
|
-
"@tramvai/react": "2.
|
|
24
|
-
"@tramvai/state": "2.
|
|
25
|
-
"@tramvai/test-jsdom": "2.
|
|
26
|
-
"@tramvai/test-mocks": "2.
|
|
27
|
-
"@tramvai/tokens-common": "2.
|
|
23
|
+
"@tramvai/react": "2.29.0",
|
|
24
|
+
"@tramvai/state": "2.29.0",
|
|
25
|
+
"@tramvai/test-jsdom": "2.29.0",
|
|
26
|
+
"@tramvai/test-mocks": "2.29.0",
|
|
27
|
+
"@tramvai/tokens-common": "2.29.0",
|
|
28
28
|
"tslib": "^2.4.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|