diff --git a/.eslintrc.js b/.eslintrc.js index 393b313..f338bb4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -26,4 +26,11 @@ module.exports = { 'react/jsx-indent': ['error', 2], 'react/jsx-indent-props': ['error', 2], }, + overrides: [ + { + // Test files only + files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'], + extends: ['plugin:testing-library/react'], + }, + ], }; diff --git a/bun.lockb b/bun.lockb index 0ef1ad3..a85073c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/jest-setup.ts b/jest-setup.ts new file mode 100644 index 0000000..1d3ff30 --- /dev/null +++ b/jest-setup.ts @@ -0,0 +1 @@ +import '@testing-library/react-native/extend-expect'; diff --git a/package.json b/package.json index 1847c22..82b7f29 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "main": "node_modules/expo/AppEntry.js", "scripts": { "start": "expo start", + "test": "jest", "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web", @@ -41,6 +42,8 @@ }, "devDependencies": { "@babel/core": "^7.20.0", + "@testing-library/react-native": "^12.5.0", + "@types/jest": "^29.5.12", "@types/react": "~18.2.14", "@typescript-eslint/eslint-plugin": "^6.4.0", "babel-plugin-module-resolver": "^5.0.0", @@ -52,10 +55,19 @@ "eslint-plugin-prettier": "^5.1.2", "eslint-plugin-promise": "^6.0.0", "eslint-plugin-react": "^7.33.2", + "eslint-plugin-testing-library": "^6.2.2", "husky": "^8.0.3", + "jest": "^29.7.0", + "jest-expo": "^50.0.4", "prettier": "^3.1.1", "tailwindcss": "3.3.2", "typescript": "*" }, + "jest": { + "preset": "jest-expo", + "transformIgnorePatterns": [ + "node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)" + ] + }, "private": true } diff --git a/src/components/core/Button.test.tsx b/src/components/core/Button.test.tsx new file mode 100644 index 0000000..45226f8 --- /dev/null +++ b/src/components/core/Button.test.tsx @@ -0,0 +1,32 @@ +import { render, screen, fireEvent, waitFor } from '@testing-library/react-native'; + +import Button from './Button'; + +describe('Button', () => { + const buttonTitle = 'Close'; + it('should render correctly', () => { + render(