@ryanbrandt/react-testing-utils 0.5.0 → 0.6.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 +11 -8
- package/dist/{@types/AbstractMockComponent.d.ts → AbstractMockComponent.d.ts} +5 -1
- package/dist/JestUtilities.d.ts +20 -0
- package/dist/{@types/MockClassComponent.d.ts → MockClassComponent.d.ts} +3 -2
- package/dist/{@types/MockFunctionComponent.d.ts → MockFunctionComponent.d.ts} +3 -2
- package/dist/{@types/index.d.ts → index.d.ts} +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +58 -43
package/README.md
CHANGED
|
@@ -16,17 +16,20 @@ npm install @ryanbrandt/react-testing-utils
|
|
|
16
16
|
|
|
17
17
|
```json
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"@testing-library/dom": "
|
|
20
|
-
"@testing-library/jest-dom": "
|
|
21
|
-
"@testing-library/react": "
|
|
22
|
-
"@testing-library/user-event": "
|
|
23
|
-
"jest": "
|
|
24
|
-
"jest-environment-jsdom": "
|
|
25
|
-
"react": "
|
|
26
|
-
"react-dom": "
|
|
19
|
+
"@testing-library/dom": "^8.13.0 || ^9.0.0 || ^10.0.0",
|
|
20
|
+
"@testing-library/jest-dom": "^5.14.1 || ^6.0.0 || ^7.0.0",
|
|
21
|
+
"@testing-library/react": "^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
22
|
+
"@testing-library/user-event": "^14.1.0",
|
|
23
|
+
"jest": "^28.1.0 || ^29.0.0 || ^30.0.0",
|
|
24
|
+
"jest-environment-jsdom": "^28.1.0 || ^29.0.0 || ^30.0.0",
|
|
25
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
26
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
27
27
|
}
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
React 19 needs `@testing-library/react` 16.1 or later. The type declarations use
|
|
31
|
+
`React.JSX`, so TypeScript consumers need `@types/react` 18.2.6 or later.
|
|
32
|
+
|
|
30
33
|
## API
|
|
31
34
|
|
|
32
35
|
### Mocking Function Components
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
1
|
+
/// <reference types="jest" preserve="true" />
|
|
2
2
|
import "@testing-library/jest-dom";
|
|
3
3
|
/**
|
|
4
4
|
* Abstract base mock component class
|
|
@@ -12,6 +12,10 @@ declare abstract class AbstractMockComponent<T> {
|
|
|
12
12
|
DATA_TEST_ID: string;
|
|
13
13
|
constructor();
|
|
14
14
|
private _buildPropsExpectation;
|
|
15
|
+
/**
|
|
16
|
+
* The props argument of each call to the mock, in call order
|
|
17
|
+
*/
|
|
18
|
+
private get _propsByCall();
|
|
15
19
|
/**
|
|
16
20
|
* Retrieves the root element of the mocked component, which will
|
|
17
21
|
* always be a div with this.DATA_TEST_ID applied
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="jest" preserve="true" />
|
|
2
|
+
type AnyFunction = (...args: any[]) => any;
|
|
3
|
+
/**
|
|
4
|
+
* Type helpers for values mocked with `jest.mock()`
|
|
5
|
+
*
|
|
6
|
+
* Jest's built-in `jest.mocked()` is the equivalent of both helpers.
|
|
7
|
+
*/
|
|
8
|
+
declare class JestUtilities {
|
|
9
|
+
/**
|
|
10
|
+
* Types a function mocked by `jest.mock()` as a Jest mock function
|
|
11
|
+
* @param actual The mocked function
|
|
12
|
+
*/
|
|
13
|
+
static assertAsMockFunction: <T extends AnyFunction>(actual: T) => jest.MockedFunction<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Types a class mocked by `jest.mock()` as a Jest mock class
|
|
16
|
+
* @param actual The mocked class
|
|
17
|
+
*/
|
|
18
|
+
static assertAsMockClass: <T extends jest.Constructable>(actual: T) => jest.MockedClass<T>;
|
|
19
|
+
}
|
|
20
|
+
export default JestUtilities;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
1
|
+
/// <reference types="jest" preserve="true" />
|
|
2
2
|
import "@testing-library/jest-dom";
|
|
3
|
+
import type { ComponentClass, JSX } from "react";
|
|
3
4
|
import AbstractMockComponent from "./AbstractMockComponent";
|
|
4
|
-
|
|
5
|
+
type ReactClassComponentWithProps<T> = ComponentClass<T>;
|
|
5
6
|
/**
|
|
6
7
|
* A standard mock class component
|
|
7
8
|
*
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
1
|
+
/// <reference types="jest" preserve="true" />
|
|
2
2
|
import "@testing-library/jest-dom";
|
|
3
|
+
import type { FunctionComponent, JSX } from "react";
|
|
3
4
|
import AbstractMockComponent from "./AbstractMockComponent";
|
|
4
|
-
|
|
5
|
+
type ReactFunctionComponentWithProps<T> = FunctionComponent<T>;
|
|
5
6
|
/**
|
|
6
7
|
* A standard mock function component instance
|
|
7
8
|
*
|
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as t}from"react/jsx-runtime";import"@testing-library/jest-dom";import{screen as e}from"@testing-library/react";import o from"@testing-library/user-event";class
|
|
1
|
+
import{jsx as t}from"react/jsx-runtime";import"@testing-library/jest-dom";import{screen as e}from"@testing-library/react";import o from"@testing-library/user-event";class s{_mock;receivedProps;DATA_TEST_ID;constructor(){this.DATA_TEST_ID=Math.random().toString(36).slice(2)}_buildPropsExpectation=t=>expect.objectContaining(t);get _propsByCall(){return this._mock.mock.calls.map(([t])=>t)}get mockRoot(){return e.getByTestId(this.DATA_TEST_ID)}get mockRoots(){return e.getAllByTestId(this.DATA_TEST_ID)}assertCalledWith=t=>{expect(this._propsByCall).toContainEqual(this._buildPropsExpectation(t))};assertLastCalledWith=t=>{this.assertNthCalledWith(t,this._propsByCall.length)};assertNthCalledWith=(t,e)=>{const o=this._propsByCall;if(e<1||e>o.length)throw new Error(`Expected a call #${e}, but the component was called ${o.length} time(s)`);expect(o[e-1]).toEqual(this._buildPropsExpectation(t))};assertOnScreen=(t=!0)=>{t?expect(this.mockRoots.length).toBeGreaterThanOrEqual(1):expect(this.mockRoot).toBeInTheDocument()};assertNotOnScreen=()=>{expect(()=>this.mockRoot).toThrow()};click=async(t=this.mockRoot.firstChild)=>{await o.click(t)};clickInstance=async t=>{await this.click(this.mockRoots[t].firstChild)};type=async(t,e=this.mockRoot.firstChild)=>{await o.type(e,t)};typeInstance=async(t,e)=>{await this.type(t,this.mockRoots[e].firstChild)}}class i extends s{constructor(t){super(),this._mock=jest.mocked(t,{shallow:!0}),this._configureMockImplementation()}_configureMockImplementation=e=>{this._mock.mockImplementation(o=>(this.receivedProps=o,{render:()=>t("div",{"data-testid":this.DATA_TEST_ID,children:e&&e(o)})}))};get __OVERRIDE__mock(){return this._mock}mockRenderReturnValue=t=>{this._configureMockImplementation(()=>t)};mockRenderImplementation=t=>{this._configureMockImplementation(e=>t(e))}}class c extends s{constructor(t){super(),this._mock=jest.mocked(t),this._configureMockImplementation()}_configureMockImplementation=e=>{this._mock.mockImplementation(o=>(this.receivedProps=o,t("div",{"data-testid":this.DATA_TEST_ID,children:e&&e(o)})))};get __OVERRIDE__mock(){return this._mock}mockReturnValue=t=>{this._configureMockImplementation(()=>t)};mockImplementation=t=>{this._configureMockImplementation(e=>t(e))}}class n{static assertAsMockFunction=t=>t;static assertAsMockClass=t=>t}export{n as JestUtilities,i as MockClassComponentWrapper,c as MockFunctionComponentWrapper};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/AbstractMockComponent.tsx","../src/MockClassComponent.tsx","../src/MockFunctionComponent.tsx"],"sourcesContent":[null,null,null],"names":["AbstractMockComponent","_mock","receivedProps","DATA_TEST_ID","constructor","this","Math","random","toString","slice","_buildPropsExpectation","props","expect","objectContaining","anything","mockRoot","screen","getByTestId","mockRoots","getAllByTestId","assertCalledWith","toHaveBeenCalledWith","assertLastCalledWith","toHaveBeenLastCalledWith","assertNthCalledWith","n","toHaveBeenNthCalledWith","assertOnScreen","allowMultiple","length","toBeGreaterThanOrEqual","toBeInTheDocument","assertNotOnScreen","toThrow","click","async","root","firstChild","userEvent","clickInstance","instanceIndex","type","value","typeInstance","MockClassComponent","actual","super","jest","mocked","_configureMockImplementation","valueGenerator","mockImplementation","render","_jsx","children","__OVERRIDE__mock","mockRenderReturnValue","mockRenderImplementation","implementation","MockFunctionComponent","mockReturnValue"],"mappings":"qKAOA,MAAeA,EACHC,MAEVC,cAKAC,aAEAC,cACEC,KAAKF,aAAeG,KAAKC,SAASC,SAAS,IAAIC,MAAM,GAI/CC,uBAA0BC,GAAsB,CACtDC,OAAOC,iBAAiB,IACnBF,IAELC,OAAOE,YAYLC,eACF,OAAOC,EAAOC,YAAYZ,KAAKF,cAY7Be,gBACF,OAAOF,EAAOG,eAAed,KAAKF,cAOpCiB,iBAAoBT,IAClBC,OAAOP,KAAKJ,OAAOoB,wBACdhB,KAAKK,uBAAuBC,KAQnCW,qBAAwBX,IACtBC,OAAOP,KAAKJ,OAAOsB,4BACdlB,KAAKK,uBAAuBC,KASnCa,oBAAsB,CAACb,EAAmBc,KACxCb,OAAOP,KAAKJ,OAAOyB,wBACjBD,KACGpB,KAAKK,uBAAuBC,KAWnCgB,eAAiB,CAACC,GAAgB,KAC5BA,EACFhB,OAAOP,KAAKa,UAAUW,QAAQC,uBAAuB,GAErDlB,OAAOP,KAAKU,UAAUgB,qBAO1BC,kBAAoB,KAClBpB,QAAO,IAAMP,KAAKU,WAAUkB,WAc9BC,MAAQC,MACNC,EAAO/B,KAAKU,SAASsB,oBAEfC,EAAUJ,MAAME,IAYxBG,cAAgBJ,MAAOK,UACfnC,KAAK6B,MAAM7B,KAAKa,UAAUsB,GAAeH,aAcjDI,KAAON,MACLO,EACAN,EAAO/B,KAAKU,SAASsB,oBAEfC,EAAUG,KAAKL,EAAMM,IAU7BC,aAAeR,MACbO,EACAF,WAEMnC,KAAKoC,KACTC,EACArC,KAAKa,UAAUsB,GAAeH,aC7JpC,MAAMO,UAA8B5C,EAGlCI,YAAYyC,GACVC,QACAzC,KAAKJ,MAAQ8C,KAAKC,OAAOH,GAEzBxC,KAAK4C,+BAGGA,6BACRC,IAIA7C,KAAKJ,MAAMkD,oBAAoBxC,IAC7BN,KAAKH,cAAgBS,EAEd,CACLyC,OAAQ,IACNC,uBAAkBhD,KAAKF,aAAYmD,SAChCJ,GAAkBA,EAAevC,UAYxC4C,uBACF,OAAOlD,KAAKJ,MAOduD,sBAAyBd,IACvBrC,KAAK4C,8BAA6B,IAAMP,KAO1Ce,yBACEC,IAEArD,KAAK4C,8BAA8BtC,GAAU+C,EAAe/C,MCpDhE,MAAMgD,UAAiC3D,EAKrCI,YAAYyC,GACVC,QACAzC,KAAKJ,MAAQ8C,KAAKC,OAAOH,GAEzBxC,KAAK4C,+BAGGA,6BACRC,IAEA7C,KAAKJ,MAAMkD,oBAAoBxC,IAC7BN,KAAKH,cAAgBS,EAGnB0C,EAAA,MAAA,CAAA,cAAkBhD,KAAKF,aACpBmD,SAAAJ,GAAkBA,EAAevC,SAWtC4C,uBACF,OAAOlD,KAAKJ,MAOd2D,gBAAmBlB,IACjBrC,KAAK4C,8BAA6B,IAAMP,KAO1CS,mBACEO,IAEArD,KAAK4C,8BAA8BtC,GAAU+C,EAAe/C"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/AbstractMockComponent.tsx","../src/MockClassComponent.tsx","../src/MockFunctionComponent.tsx","../src/JestUtilities.ts"],"sourcesContent":["// Keep the jest global types in the emitted declarations (TS 5.5+ no longer adds this).\n/// <reference types=\"jest\" preserve=\"true\" />\nimport \"@testing-library/jest-dom\";\nimport { screen } from \"@testing-library/react\";\nimport userEvent from \"@testing-library/user-event\";\n\n/**\n * Abstract base mock component class\n */\nabstract class AbstractMockComponent<T> {\n protected _mock!: jest.Mocked<unknown>;\n\n receivedProps!: T;\n\n /**\n * The data-testid applied to the component mocks\n */\n DATA_TEST_ID: string;\n\n constructor() {\n this.DATA_TEST_ID = Math.random().toString(36).slice(2);\n }\n\n // The assertions match only the props (first) argument. What React passes\n // as the second argument depends on the version: React 19 passes\n // `undefined` to function components.\n private _buildPropsExpectation = (props: Partial<T>): unknown =>\n expect.objectContaining(props);\n\n /**\n * The props argument of each call to the mock, in call order\n */\n private get _propsByCall(): unknown[] {\n return (this._mock as jest.Mock).mock.calls.map(([props]) => props);\n }\n\n /**\n * Retrieves the root element of the mocked component, which will\n * always be a div with this.DATA_TEST_ID applied\n *\n * If more than one instance of the component or no instances of the component\n * are on the screen this method will throw\n *\n * @see mockRoots\n */\n get mockRoot() {\n return screen.getByTestId(this.DATA_TEST_ID);\n }\n\n /**\n * Retrieves the root elements of all of the mocked component instances, which will\n * always be a div with this.DATA_TEST_ID applied\n *\n * Can be used when one or many instances of the mock component exist on the screen.\n * If no instances exist this method will throw\n *\n * @see mockRoot\n */\n get mockRoots() {\n return screen.getAllByTestId(this.DATA_TEST_ID);\n }\n\n /**\n * Asserts that the mock component was called with the provided subset of props\n * @param props The subset of props to match against\n */\n assertCalledWith = (props: Partial<T>): void => {\n expect(this._propsByCall).toContainEqual(\n this._buildPropsExpectation(props),\n );\n };\n\n /**\n * Asserts that the mock component was last called with the provided subset of props\n * @param props The subset of props to match against\n */\n assertLastCalledWith = (props: Partial<T>): void => {\n this.assertNthCalledWith(props, this._propsByCall.length);\n };\n\n /**\n * Asserts that the mock component was nth called with the provided subset of props\n * @param props The subset of props to match against\n * @param n The render number to check against\n */\n assertNthCalledWith = (props: Partial<T>, n: number): void => {\n const propsByCall = this._propsByCall;\n\n // Fail clearly for a call that never happened. Before Jest 30,\n // expect(undefined).toEqual(objectContaining({})) passes.\n if (n < 1 || n > propsByCall.length) {\n throw new Error(\n `Expected a call #${n}, but the component was called ${propsByCall.length} time(s)`,\n );\n }\n\n expect(propsByCall[n - 1]).toEqual(this._buildPropsExpectation(props));\n };\n\n /**\n * Asserts that an instance of the component exists within the document\n * @param allowMultiple Optional boolean to allow for multiple instances\n * of the component to exist. When set false, if more than 1 instance\n * of the component is on the screen this assertion will fail.\n * @default true\n */\n assertOnScreen = (allowMultiple = true): void => {\n if (allowMultiple) {\n expect(this.mockRoots.length).toBeGreaterThanOrEqual(1);\n } else {\n expect(this.mockRoot).toBeInTheDocument();\n }\n };\n\n /**\n * Asserts that the component is not currently rendered within the document\n */\n assertNotOnScreen = (): void => {\n expect(() => this.mockRoot).toThrow();\n };\n\n /**\n * Clicks the root element defined in the mock component's return value/implementation\n * This method will throw if no or more than a single instance of the mock component\n * exists on the screen\n *\n * @param root The root element to click\n * @default this.mockRoot.firstChild\n *\n * @see clickInstance\n *\n */\n click = async (\n root = this.mockRoot.firstChild as HTMLElement,\n ): Promise<void> => {\n await userEvent.click(root);\n };\n\n /**\n * Clicks the root element of a specific instance of the mock component as defined in the\n * mock return value/implementation.This method will throw if the provided index is not found.\n *\n * @param instanceIndex The index of the instance which should be clicked\n *\n * @see click\n *\n */\n clickInstance = async (instanceIndex: number): Promise<void> => {\n await this.click(this.mockRoots[instanceIndex].firstChild as HTMLElement);\n };\n\n /**\n * Types into the root element of your mock. This method will throw if the root element\n * does not support typing or if there are none or mulitple instances of the mock on the\n * screen.\n *\n * @param value The value to type\n * @param root The root element to type into\n * @default this.mockRoot.firstChild\n *\n * @see typeInstance\n */\n type = async (\n value: string,\n root = this.mockRoot.firstChild as HTMLElement,\n ): Promise<void> => {\n await userEvent.type(root, value);\n };\n\n /**\n * Types into the root element of a specific instance of the mock component. This method will throw\n * if the root element does not support typing or if the provided instance index is not found.\n *\n * @param value The value to type\n * @param instanceIndex The index of the instance to type into\n */\n typeInstance = async (\n value: string,\n instanceIndex: number,\n ): Promise<void> => {\n await this.type(\n value,\n this.mockRoots[instanceIndex].firstChild as HTMLElement,\n );\n };\n}\n\nexport default AbstractMockComponent;\n","// Keep the jest global types in the emitted declarations (TS 5.5+ no longer adds this).\n/// <reference types=\"jest\" preserve=\"true\" />\nimport \"@testing-library/jest-dom\";\nimport type { ComponentClass, JSX } from \"react\";\n\nimport AbstractMockComponent from \"@lib/AbstractMockComponent\";\n\ntype ReactClassComponentWithProps<T> = ComponentClass<T>;\n\n/**\n * A standard mock class component\n *\n * @example\n * jest.mock(\"path/to/my/class/component\");\n * const mockMyClassComponent = new MockClassComponent(MyClassComponent);\n */\nclass MockClassComponent<T> extends AbstractMockComponent<T> {\n declare protected _mock: jest.MockedObject<ReactClassComponentWithProps<T>>;\n\n constructor(actual: ReactClassComponentWithProps<T>) {\n super();\n this._mock = jest.mocked(actual, { shallow: true });\n\n this._configureMockImplementation();\n }\n\n protected _configureMockImplementation = (\n valueGenerator?: (props: T) => JSX.Element | null,\n ): void => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this._mock.mockImplementation((props) => {\n this.receivedProps = props;\n\n return {\n render: () => (\n <div data-testid={this.DATA_TEST_ID}>\n {valueGenerator && valueGenerator(props)}\n </div>\n ),\n };\n });\n };\n\n /**\n * Not recommended, retrieves the actual mocked component instance\n *\n * Only should be used when truly necessary\n */\n get __OVERRIDE__mock() {\n return this._mock;\n }\n\n /**\n * Mocks the return value of the render method\n * @param value The value render should return\n */\n mockRenderReturnValue = (value: JSX.Element | null): void => {\n this._configureMockImplementation(() => value);\n };\n\n /**\n * Mocks the implementation of the render method\n * @param implementation The implementation to apply to render\n */\n mockRenderImplementation = (\n implementation: (props: T) => JSX.Element | null,\n ): void => {\n this._configureMockImplementation((props) => implementation(props));\n };\n}\n\nexport default MockClassComponent;\n","// Keep the jest global types in the emitted declarations (TS 5.5+ no longer adds this).\n/// <reference types=\"jest\" preserve=\"true\" />\nimport \"@testing-library/jest-dom\";\nimport type { FunctionComponent, JSX } from \"react\";\n\nimport AbstractMockComponent from \"@lib/AbstractMockComponent\";\n\ntype ReactFunctionComponentWithProps<T> = FunctionComponent<T>;\n\n/**\n * A standard mock function component instance\n *\n * @example\n * jest.mock(\"path/to/my/function/component\");\n * const mockMyFunctionComponent = new MockFunctionComponent(MyFunctionComponent);\n */\nclass MockFunctionComponent<T> extends AbstractMockComponent<T> {\n declare protected _mock: jest.MockedFunction<\n ReactFunctionComponentWithProps<T>\n >;\n\n constructor(actual: ReactFunctionComponentWithProps<T>) {\n super();\n this._mock = jest.mocked(actual);\n\n this._configureMockImplementation();\n }\n\n protected _configureMockImplementation = (\n valueGenerator?: (props: T) => JSX.Element | null,\n ): void => {\n this._mock.mockImplementation((props) => {\n this.receivedProps = props;\n\n return (\n <div data-testid={this.DATA_TEST_ID}>\n {valueGenerator && valueGenerator(props)}\n </div>\n );\n });\n };\n\n /**\n * Not recommended, retrieves the actual mocked component instance\n *\n * Only should be used when truly necessary\n */\n get __OVERRIDE__mock() {\n return this._mock;\n }\n\n /**\n * Mocks the return value of the function component\n * @param value The value the mocked function component should return\n */\n mockReturnValue = (value: JSX.Element | null): void => {\n this._configureMockImplementation(() => value);\n };\n\n /**\n * Mocks the implementation of the function component\n * @param implementation The implementation to apply to the mock function component\n */\n mockImplementation = (\n implementation: (props: T) => JSX.Element | null,\n ): void => {\n this._configureMockImplementation((props) => implementation(props));\n };\n}\n\nexport default MockFunctionComponent;\n","// Keep the jest global types in the emitted declarations (TS 5.5+ no longer adds this).\n/// <reference types=\"jest\" preserve=\"true\" />\n// Same constraint as jest.MockedFunction; `unknown` would reject most functions.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyFunction = (...args: any[]) => any;\n\n/**\n * Type helpers for values mocked with `jest.mock()`\n *\n * Jest's built-in `jest.mocked()` is the equivalent of both helpers.\n */\nclass JestUtilities {\n /**\n * Types a function mocked by `jest.mock()` as a Jest mock function\n * @param actual The mocked function\n */\n static assertAsMockFunction = <T extends AnyFunction>(\n actual: T,\n ): jest.MockedFunction<T> => {\n const mockedFunction = actual as jest.MockedFunction<T>;\n\n return mockedFunction;\n };\n\n /**\n * Types a class mocked by `jest.mock()` as a Jest mock class\n * @param actual The mocked class\n */\n static assertAsMockClass = <T extends jest.Constructable>(\n actual: T,\n ): jest.MockedClass<T> => {\n const mockedClass = actual as jest.MockedClass<T>;\n\n return mockedClass;\n };\n}\n\nexport default JestUtilities;\n"],"names":["AbstractMockComponent","_mock","receivedProps","DATA_TEST_ID","constructor","this","Math","random","toString","slice","_buildPropsExpectation","props","expect","objectContaining","_propsByCall","mock","calls","map","mockRoot","screen","getByTestId","mockRoots","getAllByTestId","assertCalledWith","toContainEqual","assertLastCalledWith","assertNthCalledWith","length","n","propsByCall","Error","toEqual","assertOnScreen","allowMultiple","toBeGreaterThanOrEqual","toBeInTheDocument","assertNotOnScreen","toThrow","click","async","root","firstChild","userEvent","clickInstance","instanceIndex","type","value","typeInstance","MockClassComponent","actual","super","jest","mocked","shallow","_configureMockImplementation","valueGenerator","mockImplementation","render","_jsx","children","__OVERRIDE__mock","mockRenderReturnValue","mockRenderImplementation","implementation","MockFunctionComponent","mockReturnValue","JestUtilities","static"],"mappings":"qKASA,MAAeA,EACHC,MAEVC,cAKAC,aAEA,WAAAC,GACEC,KAAKF,aAAeG,KAAKC,SAASC,SAAS,IAAIC,MAAM,EACvD,CAKQC,uBAA0BC,GAChCC,OAAOC,iBAAiBF,GAK1B,gBAAYG,GACV,OAAQT,KAAKJ,MAAoBc,KAAKC,MAAMC,IAAI,EAAEN,KAAWA,EAC/D,CAWA,YAAIO,GACF,OAAOC,EAAOC,YAAYf,KAAKF,aACjC,CAWA,aAAIkB,GACF,OAAOF,EAAOG,eAAejB,KAAKF,aACpC,CAMAoB,iBAAoBZ,IAClBC,OAAOP,KAAKS,cAAcU,eACxBnB,KAAKK,uBAAuBC,KAQhCc,qBAAwBd,IACtBN,KAAKqB,oBAAoBf,EAAON,KAAKS,aAAaa,SAQpDD,oBAAsB,CAACf,EAAmBiB,KACxC,MAAMC,EAAcxB,KAAKS,aAIzB,GAAIc,EAAI,GAAKA,EAAIC,EAAYF,OAC3B,MAAM,I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CAAA,cAAkBrD,KAAKF,aAAYwD,SAChCJ,GAAkBA,EAAe5C,QAW1C,oBAAIiD,GACF,OAAOvD,KAAKJ,KACd,CAMAgE,gBAAmBnB,IACjBzC,KAAKiD,6BAA6B,IAAMR,IAO1CU,mBACEO,IAEA1D,KAAKiD,6BAA8B3C,GAAUoD,EAAepD,KCvDhE,MAAMuD,EAKJC,4BACElB,GAEuBA,EASzBkB,yBACElB,GAEoBA"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react/jsx-runtime");require("@testing-library/jest-dom");var e=require("@testing-library/react")
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react/jsx-runtime");require("@testing-library/jest-dom");var e=require("@testing-library/react"),s=require("@testing-library/user-event");class o{_mock;receivedProps;DATA_TEST_ID;constructor(){this.DATA_TEST_ID=Math.random().toString(36).slice(2)}_buildPropsExpectation=t=>expect.objectContaining(t);get _propsByCall(){return this._mock.mock.calls.map(([t])=>t)}get mockRoot(){return e.screen.getByTestId(this.DATA_TEST_ID)}get mockRoots(){return e.screen.getAllByTestId(this.DATA_TEST_ID)}assertCalledWith=t=>{expect(this._propsByCall).toContainEqual(this._buildPropsExpectation(t))};assertLastCalledWith=t=>{this.assertNthCalledWith(t,this._propsByCall.length)};assertNthCalledWith=(t,e)=>{const s=this._propsByCall;if(e<1||e>s.length)throw new Error(`Expected a call #${e}, but the component was called ${s.length} time(s)`);expect(s[e-1]).toEqual(this._buildPropsExpectation(t))};assertOnScreen=(t=!0)=>{t?expect(this.mockRoots.length).toBeGreaterThanOrEqual(1):expect(this.mockRoot).toBeInTheDocument()};assertNotOnScreen=()=>{expect(()=>this.mockRoot).toThrow()};click=async(t=this.mockRoot.firstChild)=>{await s.click(t)};clickInstance=async t=>{await this.click(this.mockRoots[t].firstChild)};type=async(t,e=this.mockRoot.firstChild)=>{await s.type(e,t)};typeInstance=async(t,e)=>{await this.type(t,this.mockRoots[e].firstChild)}}exports.JestUtilities=class{static assertAsMockFunction=t=>t;static assertAsMockClass=t=>t},exports.MockClassComponentWrapper=class extends o{constructor(t){super(),this._mock=jest.mocked(t,{shallow:!0}),this._configureMockImplementation()}_configureMockImplementation=e=>{this._mock.mockImplementation(s=>(this.receivedProps=s,{render:()=>t.jsx("div",{"data-testid":this.DATA_TEST_ID,children:e&&e(s)})}))};get __OVERRIDE__mock(){return this._mock}mockRenderReturnValue=t=>{this._configureMockImplementation(()=>t)};mockRenderImplementation=t=>{this._configureMockImplementation(e=>t(e))}},exports.MockFunctionComponentWrapper=class extends o{constructor(t){super(),this._mock=jest.mocked(t),this._configureMockImplementation()}_configureMockImplementation=e=>{this._mock.mockImplementation(s=>(this.receivedProps=s,t.jsx("div",{"data-testid":this.DATA_TEST_ID,children:e&&e(s)})))};get __OVERRIDE__mock(){return this._mock}mockReturnValue=t=>{this._configureMockImplementation(()=>t)};mockImplementation=t=>{this._configureMockImplementation(e=>t(e))}};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/AbstractMockComponent.tsx","../src/MockClassComponent.tsx","../src/MockFunctionComponent.tsx"],"sourcesContent":[null,null,null],"names":["AbstractMockComponent","_mock","receivedProps","DATA_TEST_ID","constructor","this","Math","random","toString","slice","_buildPropsExpectation","props","expect","objectContaining","anything","mockRoot","screen","getByTestId","mockRoots","getAllByTestId","assertCalledWith","toHaveBeenCalledWith","assertLastCalledWith","toHaveBeenLastCalledWith","assertNthCalledWith","n","toHaveBeenNthCalledWith","assertOnScreen","allowMultiple","length","toBeGreaterThanOrEqual","toBeInTheDocument","assertNotOnScreen","toThrow","click","async","root","firstChild","userEvent","clickInstance","instanceIndex","type","value","typeInstance","actual","super","jest","mocked","_configureMockImplementation","valueGenerator","mockImplementation","render","_jsx","children","__OVERRIDE__mock","mockRender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kD,SAChCJ,GAAkBA,EAAetC,UAYxC2C,uBACF,OAAOjD,KAAKJ,MAOdsD,sBAAyBb,IACvBrC,KAAK2C,8BAA6B,IAAMN,KAO1Cc,yBACEC,IAEApD,KAAK2C,8BAA8BrC,GAAU8C,EAAe9C,4CCpDhE,cAAuCX,EAKrCI,YAAYwC,GACVC,QACAxC,KAAKJ,MAAQ6C,KAAKC,OAAOH,GAEzBvC,KAAK2C,+BAGGA,6BACRC,IAEA5C,KAAKJ,MAAMiD,oBAAoBvC,IAC7BN,KAAKH,cAAgBS,EAGnByC,MAAA,MAAA,CAAA,cAAkB/C,KAAKF,aACpBkD,SAAAJ,GAAkBA,EAAetC,SAWtC2C,uBACF,OAAOjD,KAAKJ,MAOdyD,gBAAmBhB,IACjBrC,KAAK2C,8BAA6B,IAAMN,KAO1CQ,mBACEO,IAEApD,KAAK2C,8BAA8BrC,GAAU8C,EAAe9C"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/AbstractMockComponent.tsx","../src/JestUtilities.ts","../src/MockClassComponent.tsx","../src/MockFunctionComponent.tsx"],"sourcesContent":["// Keep the jest global types in the emitted declarations (TS 5.5+ no longer adds this).\n/// <reference types=\"jest\" preserve=\"true\" />\nimport \"@testing-library/jest-dom\";\nimport { screen } from \"@testing-library/react\";\nimport userEvent from \"@testing-library/user-event\";\n\n/**\n * Abstract base mock component class\n */\nabstract class AbstractMockComponent<T> {\n protected _mock!: jest.Mocked<unknown>;\n\n receivedProps!: T;\n\n /**\n * The data-testid applied to the component mocks\n */\n DATA_TEST_ID: string;\n\n constructor() {\n this.DATA_TEST_ID = Math.random().toString(36).slice(2);\n }\n\n // The assertions match only the props (first) argument. What React passes\n // as the second argument depends on the version: React 19 passes\n // `undefined` to function components.\n private _buildPropsExpectation = (props: Partial<T>): unknown =>\n expect.objectContaining(props);\n\n /**\n * The props argument of each call to the mock, in call order\n */\n private get _propsByCall(): unknown[] {\n return (this._mock as jest.Mock).mock.calls.map(([props]) => props);\n }\n\n /**\n * Retrieves the root element of the mocked component, which will\n * always be a div with this.DATA_TEST_ID applied\n *\n * If more than one instance of the component or no instances of the component\n * are on the screen this method will throw\n *\n * @see mockRoots\n */\n get mockRoot() {\n return screen.getByTestId(this.DATA_TEST_ID);\n }\n\n /**\n * Retrieves the root elements of all of the mocked component instances, which will\n * always be a div with this.DATA_TEST_ID applied\n *\n * Can be used when one or many instances of the mock component exist on the screen.\n * If no instances exist this method will throw\n *\n * @see mockRoot\n */\n get mockRoots() {\n return screen.getAllByTestId(this.DATA_TEST_ID);\n }\n\n /**\n * Asserts that the mock component was called with the provided subset of props\n * @param props The subset of props to match against\n */\n assertCalledWith = (props: Partial<T>): void => {\n expect(this._propsByCall).toContainEqual(\n this._buildPropsExpectation(props),\n );\n };\n\n /**\n * Asserts that the mock component was last called with the provided subset of props\n * @param props The subset of props to match against\n */\n assertLastCalledWith = (props: Partial<T>): void => {\n this.assertNthCalledWith(props, this._propsByCall.length);\n };\n\n /**\n * Asserts that the mock component was nth called with the provided subset of props\n * @param props The subset of props to match against\n * @param n The render number to check against\n */\n assertNthCalledWith = (props: Partial<T>, n: number): void => {\n const propsByCall = this._propsByCall;\n\n // Fail clearly for a call that never happened. Before Jest 30,\n // expect(undefined).toEqual(objectContaining({})) passes.\n if (n < 1 || n > propsByCall.length) {\n throw new Error(\n `Expected a call #${n}, but the component was called ${propsByCall.length} time(s)`,\n );\n }\n\n expect(propsByCall[n - 1]).toEqual(this._buildPropsExpectation(props));\n };\n\n /**\n * Asserts that an instance of the component exists within the document\n * @param allowMultiple Optional boolean to allow for multiple instances\n * of the component to exist. When set false, if more than 1 instance\n * of the component is on the screen this assertion will fail.\n * @default true\n */\n assertOnScreen = (allowMultiple = true): void => {\n if (allowMultiple) {\n expect(this.mockRoots.length).toBeGreaterThanOrEqual(1);\n } else {\n expect(this.mockRoot).toBeInTheDocument();\n }\n };\n\n /**\n * Asserts that the component is not currently rendered within the document\n */\n assertNotOnScreen = (): void => {\n expect(() => this.mockRoot).toThrow();\n };\n\n /**\n * Clicks the root element defined in the mock component's return value/implementation\n * This method will throw if no or more than a single instance of the mock component\n * exists on the screen\n *\n * @param root The root element to click\n * @default this.mockRoot.firstChild\n *\n * @see clickInstance\n *\n */\n click = async (\n root = this.mockRoot.firstChild as HTMLElement,\n ): Promise<void> => {\n await userEvent.click(root);\n };\n\n /**\n * Clicks the root element of a specific instance of the mock component as defined in the\n * mock return value/implementation.This method will throw if the provided index is not found.\n *\n * @param instanceIndex The index of the instance which should be clicked\n *\n * @see click\n *\n */\n clickInstance = async (instanceIndex: number): Promise<void> => {\n await this.click(this.mockRoots[instanceIndex].firstChild as HTMLElement);\n };\n\n /**\n * Types into the root element of your mock. This method will throw if the root element\n * does not support typing or if there are none or mulitple instances of the mock on the\n * screen.\n *\n * @param value The value to type\n * @param root The root element to type into\n * @default this.mockRoot.firstChild\n *\n * @see typeInstance\n */\n type = async (\n value: string,\n root = this.mockRoot.firstChild as HTMLElement,\n ): Promise<void> => {\n await userEvent.type(root, value);\n };\n\n /**\n * Types into the root element of a specific instance of the mock component. This method will throw\n * if the root element does not support typing or if the provided instance index is not found.\n *\n * @param value The value to type\n * @param instanceIndex The index of the instance to type into\n */\n typeInstance = async (\n value: string,\n instanceIndex: number,\n ): Promise<void> => {\n await this.type(\n value,\n this.mockRoots[instanceIndex].firstChild as HTMLElement,\n );\n };\n}\n\nexport default AbstractMockComponent;\n","// Keep the jest global types in the emitted declarations (TS 5.5+ no longer adds this).\n/// <reference types=\"jest\" preserve=\"true\" />\n// Same constraint as jest.MockedFunction; `unknown` would reject most functions.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyFunction = (...args: any[]) => any;\n\n/**\n * Type helpers for values mocked with `jest.mock()`\n *\n * Jest's built-in `jest.mocked()` is the equivalent of both helpers.\n */\nclass JestUtilities {\n /**\n * Types a function mocked by `jest.mock()` as a Jest mock function\n * @param actual The mocked function\n */\n static assertAsMockFunction = <T extends AnyFunction>(\n actual: T,\n ): jest.MockedFunction<T> => {\n const mockedFunction = actual as jest.MockedFunction<T>;\n\n return mockedFunction;\n };\n\n /**\n * Types a class mocked by `jest.mock()` as a Jest mock class\n * @param actual The mocked class\n */\n static assertAsMockClass = <T extends jest.Constructable>(\n actual: T,\n ): jest.MockedClass<T> => {\n const mockedClass = actual as jest.MockedClass<T>;\n\n return mockedClass;\n };\n}\n\nexport default JestUtilities;\n","// Keep the jest global types in the emitted declarations (TS 5.5+ no longer adds this).\n/// <reference types=\"jest\" preserve=\"true\" />\nimport \"@testing-library/jest-dom\";\nimport type { ComponentClass, JSX } from \"react\";\n\nimport AbstractMockComponent from \"@lib/AbstractMockComponent\";\n\ntype ReactClassComponentWithProps<T> = ComponentClass<T>;\n\n/**\n * A standard mock class component\n *\n * @example\n * jest.mock(\"path/to/my/class/component\");\n * const mockMyClassComponent = new MockClassComponent(MyClassComponent);\n */\nclass MockClassComponent<T> extends AbstractMockComponent<T> {\n declare protected _mock: jest.MockedObject<ReactClassComponentWithProps<T>>;\n\n constructor(actual: ReactClassComponentWithProps<T>) {\n super();\n this._mock = jest.mocked(actual, { shallow: true });\n\n this._configureMockImplementation();\n }\n\n protected _configureMockImplementation = (\n valueGenerator?: (props: T) => JSX.Element | null,\n ): void => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this._mock.mockImplementation((props) => {\n this.receivedProps = props;\n\n return {\n render: () => (\n <div data-testid={this.DATA_TEST_ID}>\n {valueGenerator && valueGenerator(props)}\n </div>\n ),\n };\n });\n };\n\n /**\n * Not recommended, retrieves the actual mocked component instance\n *\n * Only should be used when truly necessary\n */\n get __OVERRIDE__mock() {\n return this._mock;\n }\n\n /**\n * Mocks the return value of the render method\n * @param value The value render should return\n */\n mockRenderReturnValue = (value: JSX.Element | null): void => {\n this._configureMockImplementation(() => value);\n };\n\n /**\n * Mocks the implementation of the render method\n * @param implementation The implementation to apply to render\n */\n mockRenderImplementation = (\n implementation: (props: T) => JSX.Element | null,\n ): void => {\n this._configureMockImplementation((props) => implementation(props));\n };\n}\n\nexport default MockClassComponent;\n","// Keep the jest global types in the emitted declarations (TS 5.5+ no longer adds this).\n/// <reference types=\"jest\" preserve=\"true\" />\nimport \"@testing-library/jest-dom\";\nimport type { FunctionComponent, JSX } from \"react\";\n\nimport AbstractMockComponent from \"@lib/AbstractMockComponent\";\n\ntype ReactFunctionComponentWithProps<T> = FunctionComponent<T>;\n\n/**\n * A standard mock function component instance\n *\n * @example\n * jest.mock(\"path/to/my/function/component\");\n * const mockMyFunctionComponent = new MockFunctionComponent(MyFunctionComponent);\n */\nclass MockFunctionComponent<T> extends AbstractMockComponent<T> {\n declare protected _mock: jest.MockedFunction<\n ReactFunctionComponentWithProps<T>\n >;\n\n constructor(actual: ReactFunctionComponentWithProps<T>) {\n super();\n this._mock = jest.mocked(actual);\n\n this._configureMockImplementation();\n }\n\n protected _configureMockImplementation = (\n valueGenerator?: (props: T) => JSX.Element | null,\n ): void => {\n this._mock.mockImplementation((props) => {\n this.receivedProps = props;\n\n return (\n <div data-testid={this.DATA_TEST_ID}>\n {valueGenerator && valueGenerator(props)}\n </div>\n );\n });\n };\n\n /**\n * Not recommended, retrieves the actual mocked component instance\n *\n * Only should be used when truly necessary\n */\n get __OVERRIDE__mock() {\n return this._mock;\n }\n\n /**\n * Mocks the return value of the function component\n * @param value The value the mocked function component should return\n */\n mockReturnValue = (value: JSX.Element | null): void => {\n this._configureMockImplementation(() => value);\n };\n\n /**\n * Mocks the implementation of the function component\n * @param implementation The implementation to apply to the mock function component\n */\n mockImplementation = (\n implementation: (props: T) => JSX.Element | null,\n ): void => {\n this._configureMockImplementation((props) => implementation(props));\n };\n}\n\nexport default MockFunctionComponent;\n"],"names":["AbstractMockComponent","_mock","receivedProps","DATA_TEST_ID","constructor","this","Math","random","toString","slice","_buildPropsExpectation","props","expect","objectContaining","_propsByCall","mock","calls","map","mockRoot","screen","getByTestId","mockRoots","getAllByTestId","assertCalledWith","toContainEqual","assertLastCalledWith","assertNthCalledWith","length","n","propsByCall","Error","toEqual","assertOnScreen","allowMultiple","toBeGreaterThanOrEqual","toBeInTheDocument","assertNotOnScreen","toThrow","click","async","root","firstChild","userEvent","clickInstance","instanceIndex","type","value","typeInstance","static","actual","super","jest","mocked","shallow","_configureMockImplementation","valueGenerator","mockImplementation","render","_jsx","children","__OVERRIDE__mock","mockRenderReturnValue","mockRenderImplementation","implementation","mockReturnValue"],"mappings":"6NASA,MAAeA,EACHC,MAEVC,cAKAC,aAEA,WAAAC,GACEC,KAAKF,aAAeG,KAAKC,SAASC,SAAS,IAAIC,MAAM,EACvD,CAKQC,uBAA0BC,GAChCC,OAAOC,iBAAiBF,GAK1B,gBAAYG,GACV,OAAQT,KAAKJ,MAAoBc,KAAKC,MAAMC,IAAI,EAAEN,KAAWA,EAC/D,CAWA,YAAIO,GACF,OAAOC,SAAOC,YAAYf,KAAKF,aACjC,CAWA,aAAIkB,GACF,OAAOF,SAAOG,eAAejB,KAAKF,aACpC,CAMAoB,iBAAoBZ,IAClBC,OAAOP,KAAKS,cAAcU,eACxBnB,KAAKK,uBAAuBC,KAQhCc,qBAAwBd,IACtBN,KAAKqB,oBAAoBf,EAAON,KAAKS,aAAaa,SAQpDD,oBAAsB,CAACf,EAAmBiB,KACxC,MAAMC,EAAcxB,KAAKS,aAIzB,GAAIc,EAAI,GAAKA,EAAIC,EAAYF,OAC3B,MAAM,IAAIG,MACR,oBAAoBF,mCAAmCC,EAAYF,kBAIvEf,OAAOiB,EAAYD,EAAI,IAAIG,QAAQ1B,KAAKK,uBAAuBC,KAUjEqB,eAAiB,CAACC,GAAgB,KAC5BA,EACFrB,OAAOP,KAAKgB,UAAUM,QAAQO,uBAAuB,GAErDtB,OAAOP,KAAKa,UAAUiB,qBAO1BC,kBAAoB,KAClBxB,OAAO,IAAMP,KAAKa,UAAUmB,WAc9BC,MAAQC,MACNC,EAAOnC,KAAKa,SAASuB,oBAEfC,EAAUJ,MAAME,IAYxBG,cAAgBJ,MAAO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
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"repository": "https://github.com/ryanbrandt/react-testing-utils",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Jest/React/RTL component unit testing utilities",
|
|
7
7
|
"author": "Ryan Brandt",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"module": "dist/index.esm.js",
|
|
10
|
-
"
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"module": "./dist/index.esm.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./dist/*": "./dist/*",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
11
20
|
"files": [
|
|
12
21
|
"dist"
|
|
13
22
|
],
|
|
@@ -15,51 +24,57 @@
|
|
|
15
24
|
"access": "public"
|
|
16
25
|
},
|
|
17
26
|
"scripts": {
|
|
27
|
+
"typecheck": "tsc -p . --noEmit",
|
|
28
|
+
"lint": "eslint . --max-warnings 0",
|
|
29
|
+
"format": "prettier --write .",
|
|
30
|
+
"format:check": "prettier --check .",
|
|
18
31
|
"test": "jest --coverage",
|
|
19
|
-
"
|
|
32
|
+
"test:react18": "REACT_VERSION=18 jest --coverage",
|
|
33
|
+
"build": "rm -rf dist && rollup -c && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json"
|
|
20
34
|
},
|
|
21
35
|
"devDependencies": {
|
|
22
|
-
"@
|
|
23
|
-
"@rollup/plugin-
|
|
24
|
-
"@rollup/plugin-typescript": "^
|
|
25
|
-
"@testing-library/dom": "^
|
|
26
|
-
"@testing-library/jest-dom": "^
|
|
27
|
-
"@testing-library/react": "^
|
|
28
|
-
"@testing-library/user-event": "^14.
|
|
29
|
-
"@types/jest": "^
|
|
30
|
-
"@types/node": "^
|
|
31
|
-
"@types/react": "^
|
|
32
|
-
"@
|
|
33
|
-
"
|
|
34
|
-
"eslint": "^
|
|
35
|
-
"eslint-
|
|
36
|
-
"eslint-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"jest": "
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"react": "
|
|
43
|
-
"react-dom": "^
|
|
44
|
-
"
|
|
45
|
-
"rollup
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"typescript": "^4.6.3",
|
|
52
|
-
"typescript-transform-paths": "^3.3.1"
|
|
36
|
+
"@eslint/js": "^10.0.1",
|
|
37
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
38
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
39
|
+
"@testing-library/dom": "^10.4.2",
|
|
40
|
+
"@testing-library/jest-dom": "^7.0.1",
|
|
41
|
+
"@testing-library/react": "^16.3.3",
|
|
42
|
+
"@testing-library/user-event": "^14.6.7",
|
|
43
|
+
"@types/jest": "^30.0.0",
|
|
44
|
+
"@types/node": "^24.19.0",
|
|
45
|
+
"@types/react": "^19.3.0",
|
|
46
|
+
"@types/react-dom": "^19.3.0",
|
|
47
|
+
"eslint": "^10.11.0",
|
|
48
|
+
"eslint-config-prettier": "^10.1.8",
|
|
49
|
+
"eslint-import-resolver-typescript": "^4.4.5",
|
|
50
|
+
"eslint-plugin-import-x": "^4.17.1",
|
|
51
|
+
"globals": "^17.12.0",
|
|
52
|
+
"jest": "^30.5.2",
|
|
53
|
+
"jest-environment-jsdom": "^30.5.2",
|
|
54
|
+
"prettier": "^3.9.9",
|
|
55
|
+
"react": "^19.3.0",
|
|
56
|
+
"react-18": "npm:react@^18.3.1",
|
|
57
|
+
"react-dom": "^19.3.0",
|
|
58
|
+
"react-dom-18": "npm:react-dom@^18.3.1",
|
|
59
|
+
"rollup": "^4.63.5",
|
|
60
|
+
"ts-jest": "^29.4.14",
|
|
61
|
+
"tsc-alias": "~1.8.17",
|
|
62
|
+
"tslib": "^2.8.1",
|
|
63
|
+
"typescript": "^6.0.3",
|
|
64
|
+
"typescript-eslint": "^8.71.0"
|
|
53
65
|
},
|
|
54
66
|
"peerDependencies": {
|
|
55
|
-
"@testing-library/dom": "
|
|
56
|
-
"@testing-library/jest-dom": "
|
|
57
|
-
"@testing-library/react": "
|
|
58
|
-
"@testing-library/user-event": "
|
|
59
|
-
"jest": "
|
|
60
|
-
"jest-environment-jsdom": "
|
|
61
|
-
"react": "
|
|
62
|
-
"react-dom": "
|
|
67
|
+
"@testing-library/dom": "^8.13.0 || ^9.0.0 || ^10.0.0",
|
|
68
|
+
"@testing-library/jest-dom": "^5.14.1 || ^6.0.0 || ^7.0.0",
|
|
69
|
+
"@testing-library/react": "^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
70
|
+
"@testing-library/user-event": "^14.1.0",
|
|
71
|
+
"jest": "^28.1.0 || ^29.0.0 || ^30.0.0",
|
|
72
|
+
"jest-environment-jsdom": "^28.1.0 || ^29.0.0 || ^30.0.0",
|
|
73
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
74
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
75
|
+
},
|
|
76
|
+
"engines": {
|
|
77
|
+
"node": ">=20.19"
|
|
63
78
|
},
|
|
64
|
-
"packageManager": "yarn@
|
|
79
|
+
"packageManager": "yarn@4.18.1"
|
|
65
80
|
}
|