diff --git a/.eslintrc.json b/.eslintrc.json index 2085a624..35ffe19f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,9 @@ { "extends": "satya164", "settings": { - "react": { "version": "16" }, + "react": { + "version": "16" + }, "import/core-modules": [ "@react-navigation/core", "@react-navigation/native", @@ -15,5 +17,11 @@ "@react-navigation/devtools" ] }, - "env": { "browser": true, "node": true } + "env": { + "browser": true, + "node": true + }, + "rules": { + "react/no-unused-prop-types": "off" + } } diff --git a/babel.config.js b/babel.config.js index 853c9fc3..f842b77f 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,22 +1,3 @@ module.exports = { - presets: [ - [ - '@babel/preset-env', - { - useBuiltIns: 'usage', - corejs: 3, - targets: { - node: 'current', - }, - }, - ], - '@babel/preset-react', - '@babel/preset-typescript', - ], - plugins: [ - '@babel/plugin-proposal-class-properties', - '@babel/plugin-proposal-optional-chaining', - '@babel/transform-flow-strip-types', - '@babel/plugin-proposal-nullish-coalescing-operator', - ], + presets: ['module:metro-react-native-babel-preset'], }; diff --git a/jest/setup.js b/jest/setup.js index 0a696142..5b0251b4 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -1,3 +1,21 @@ +/* eslint-env jest */ +/* eslint-disable import/no-extraneous-dependencies */ + +import 'react-native-gesture-handler/jestSetup'; + +jest.mock('react-native-reanimated', () => { + const Reanimated = require('react-native-reanimated/mock'); + + // The mock for `call` immediately calls the callback which is incorrect + // So we override it with a no-op + Reanimated.default.call = () => {}; + + return Reanimated; +}); + +// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing +jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper'); + const error = console.error; console.error = (...args) => diff --git a/package.json b/package.json index 4d980630..435d22c3 100644 --- a/package.json +++ b/package.json @@ -25,24 +25,17 @@ "example": "yarn --cwd example" }, "devDependencies": { - "@babel/plugin-proposal-class-properties": "^7.10.1", - "@babel/plugin-proposal-optional-chaining": "^7.10.1", - "@babel/preset-env": "^7.10.2", - "@babel/preset-flow": "^7.10.1", - "@babel/preset-react": "^7.10.1", - "@babel/preset-typescript": "^7.10.1", - "@babel/runtime": "^7.10.2", "@commitlint/config-conventional": "^8.3.4", "@types/jest": "^26.0.0", "babel-jest": "^26.0.1", "codecov": "^3.7.0", "commitlint": "^8.3.5", - "core-js": "^3.6.5", "eslint": "^7.2.0", "eslint-config-satya164": "^3.1.7", "husky": "^4.2.5", "jest": "^26.0.1", "lerna": "^3.22.1", + "metro-react-native-babel-preset": "^0.59.0", "prettier": "^2.0.5", "typescript": "^3.9.5" }, @@ -59,9 +52,6 @@ "jest": { "testEnvironment": "node", "testRegex": "/__tests__/.*\\.(test|spec)\\.(js|tsx?)$", - "transform": { - "^.+\\.(js|ts|tsx)$": "babel-jest" - }, "setupFiles": [ "/jest/setup.js" ], diff --git a/packages/bottom-tabs/package.json b/packages/bottom-tabs/package.json index 4bff7328..3851f0c0 100644 --- a/packages/bottom-tabs/package.json +++ b/packages/bottom-tabs/package.json @@ -50,6 +50,7 @@ "react-native": "~0.61.5", "react-native-safe-area-context": "^1.0.0", "react-native-screens": "^2.7.0", + "react-native-testing-library": "^2.1.0", "typescript": "^3.9.5" }, "peerDependencies": { diff --git a/packages/bottom-tabs/src/__tests__/index.test.tsx b/packages/bottom-tabs/src/__tests__/index.test.tsx new file mode 100644 index 00000000..a242a442 --- /dev/null +++ b/packages/bottom-tabs/src/__tests__/index.test.tsx @@ -0,0 +1,33 @@ +import * as React from 'react'; +import { View, Text, Button } from 'react-native'; +import { render, fireEvent } from 'react-native-testing-library'; +import { NavigationContainer, ParamListBase } from '@react-navigation/native'; +import { createBottomTabNavigator, BottomTabScreenProps } from '../index'; + +it('renders a bottom tab navigator with screens', async () => { + const Test = ({ route, navigation }: BottomTabScreenProps) => ( + + Screen {route.name} +