diff --git a/jest.config.ts b/jest.config.ts index db6c509a..69d5daec 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -19,8 +19,8 @@ const jestConfig: JestConfigWithTsJest = { 'node_modules/(?!(@react-native|react-native|react-native-drop-shadow|@gorhom/bottom-sheet|react-native-reanimated)/)', ], moduleDirectories: ['node_modules', 'src'], + setupFilesAfterEnv: ['./jest.setup.ts'], setupFiles: [ - './jest.setup.js', './node_modules/react-native-gesture-handler/jestSetup.js', './node_modules/react-native/jest/setup.js', ], diff --git a/jest.setup.js b/jest.setup.ts similarity index 58% rename from jest.setup.js rename to jest.setup.ts index 255e55df..97a98f39 100644 --- a/jest.setup.js +++ b/jest.setup.ts @@ -1,4 +1,5 @@ -// This 2 following lines are mandatory since we add and use react-native-device-info +import '@testing-library/react-native/extend-expect'; +//This 2 following lines are mandatory since we add and use react-native-device-info import mockRNDeviceInfo from 'react-native-device-info/jest/react-native-device-info-mock'; // eslint-disable-next-line no-undef jest.mock('react-native-device-info', () => mockRNDeviceInfo); diff --git a/modules.d.ts b/modules.d.ts new file mode 100644 index 00000000..f4110051 --- /dev/null +++ b/modules.d.ts @@ -0,0 +1 @@ +declare module 'react-native-device-info/jest/react-native-device-info-mock'; diff --git a/package-lock.json b/package-lock.json index 8519c8c0..6c627a76 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,8 +8,7 @@ "name": "@zerogachis/smartway-react-native-ui", "version": "0.6.1", "devDependencies": { - "@testing-library/jest-native": "^5.4.3", - "@testing-library/react-native": "^12.3.0", + "@testing-library/react-native": "^12.4.2", "@types/jest": "^29.5.5", "@types/react": "^18.2.43", "@types/react-native": "^0.70.0", @@ -4463,102 +4462,14 @@ "@sinonjs/commons": "^3.0.0" } }, - "node_modules/@testing-library/jest-native": { - "version": "5.4.3", - "resolved": "https://registry.npmjs.org/@testing-library/jest-native/-/jest-native-5.4.3.tgz", - "integrity": "sha512-/sSDGaOuE+PJ1Z9Kp4u7PQScSVVXGud59I/qsBFFJvIbcn4P6yYw6cBnBmbPF+X9aRIsTJRDl6gzw5ZkJNm66w==", - "dev": true, - "dependencies": { - "chalk": "^4.1.2", - "jest-diff": "^29.0.1", - "jest-matcher-utils": "^29.0.1", - "pretty-format": "^29.0.3", - "redent": "^3.0.0" - }, - "peerDependencies": { - "react": ">=16.0.0", - "react-native": ">=0.59", - "react-test-renderer": ">=16.0.0" - } - }, - "node_modules/@testing-library/jest-native/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/@testing-library/jest-native/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/@testing-library/jest-native/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/@testing-library/jest-native/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, - "node_modules/@testing-library/jest-native/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/@testing-library/jest-native/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/@testing-library/react-native": { - "version": "12.3.0", - "resolved": "https://registry.npmjs.org/@testing-library/react-native/-/react-native-12.3.0.tgz", - "integrity": "sha512-E2Prl8D/ey9sRgzLyfCPPmqvsevJW5tVUy4E/pBbO7nOP6OzI/jn2P3vctn/kFdkPY2aE/udlU5ZeNAben9U2A==", + "version": "12.4.2", + "resolved": "https://registry.npmjs.org/@testing-library/react-native/-/react-native-12.4.2.tgz", + "integrity": "sha512-6Uu3M+ga1iDgleS55mGBqI1GHjvKu1T0aESSHkT8dL+M3nIZkW8jZ9HqDSj2UohkMA1hlb+7PRxS+EjwllyANA==", "dev": true, "dependencies": { - "jest-matcher-utils": "^29.6.2", - "pretty-format": "^29.6.2", + "jest-matcher-utils": "^29.7.0", + "pretty-format": "^29.7.0", "redent": "^3.0.0" }, "peerDependencies": { @@ -19173,78 +19084,14 @@ "@sinonjs/commons": "^3.0.0" } }, - "@testing-library/jest-native": { - "version": "5.4.3", - "resolved": "https://registry.npmjs.org/@testing-library/jest-native/-/jest-native-5.4.3.tgz", - "integrity": "sha512-/sSDGaOuE+PJ1Z9Kp4u7PQScSVVXGud59I/qsBFFJvIbcn4P6yYw6cBnBmbPF+X9aRIsTJRDl6gzw5ZkJNm66w==", - "dev": true, - "requires": { - "chalk": "^4.1.2", - "jest-diff": "^29.0.1", - "jest-matcher-utils": "^29.0.1", - "pretty-format": "^29.0.3", - "redent": "^3.0.0" - }, - "dependencies": { - "ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "requires": { - "color-convert": "^2.0.1" - } - }, - "chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, - "requires": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - } - }, - "color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "requires": { - "color-name": "~1.1.4" - } - }, - "color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, - "has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true - }, - "supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, - "requires": { - "has-flag": "^4.0.0" - } - } - } - }, "@testing-library/react-native": { - "version": "12.3.0", - "resolved": "https://registry.npmjs.org/@testing-library/react-native/-/react-native-12.3.0.tgz", - "integrity": "sha512-E2Prl8D/ey9sRgzLyfCPPmqvsevJW5tVUy4E/pBbO7nOP6OzI/jn2P3vctn/kFdkPY2aE/udlU5ZeNAben9U2A==", + "version": "12.4.2", + "resolved": "https://registry.npmjs.org/@testing-library/react-native/-/react-native-12.4.2.tgz", + "integrity": "sha512-6Uu3M+ga1iDgleS55mGBqI1GHjvKu1T0aESSHkT8dL+M3nIZkW8jZ9HqDSj2UohkMA1hlb+7PRxS+EjwllyANA==", "dev": true, "requires": { - "jest-matcher-utils": "^29.6.2", - "pretty-format": "^29.6.2", + "jest-matcher-utils": "^29.7.0", + "pretty-format": "^29.7.0", "redent": "^3.0.0" } }, diff --git a/package.json b/package.json index fdc2eabc..4ab79da1 100644 --- a/package.json +++ b/package.json @@ -45,8 +45,7 @@ "@ZeroGachis:registry": "https://npm.pkg.github.com" }, "devDependencies": { - "@testing-library/jest-native": "^5.4.3", - "@testing-library/react-native": "^12.3.0", + "@testing-library/react-native": "^12.4.2", "@types/jest": "^29.5.5", "@types/react": "^18.2.43", "@types/react-native": "^0.70.0", diff --git a/src/__tests__/components/Badge.test.tsx b/src/__tests__/components/Badge.test.tsx index 2bb1d021..14504321 100644 --- a/src/__tests__/components/Badge.test.tsx +++ b/src/__tests__/components/Badge.test.tsx @@ -13,7 +13,7 @@ describe('MODULE | Badge', () => { , ); - expect(screen.getByText('100')).toBeDefined(); + expect(screen.getByText('100')).toBeOnTheScreen(); }); }); describe("Given a `number` and a `maxDigits` greater than number's total digit", () => { @@ -24,7 +24,7 @@ describe('MODULE | Badge', () => { , ); - expect(screen.getByText('99+')).toBeDefined(); + expect(screen.getByText('99+')).toBeOnTheScreen(); }); }); describe("Given a `number` and a `maxDigits` smaller or equal than number's total digit'", () => { @@ -35,7 +35,7 @@ describe('MODULE | Badge', () => { , ); - expect(screen.getByText('88')).toBeDefined(); + expect(screen.getByText('88')).toBeOnTheScreen(); }); }); }); diff --git a/tsconfig.json b/tsconfig.json index b50f6a5c..69d3cbc8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,6 +26,6 @@ "strict": true, "target": "esnext" }, - "include": ["src", "./.eslintrc.json"], + "include": ["src", "./.eslintrc.json", "./modules.d.ts", "./jest.setup.ts"], "exclude": ["src/components/charts/*"] }