diff --git a/jest-setup.ts b/jest-setup.ts new file mode 100644 index 0000000..9f28ad2 --- /dev/null +++ b/jest-setup.ts @@ -0,0 +1 @@ +import '@testing-library/jest-native/extend-expect'; diff --git a/package.json b/package.json index 0552a3a..a1d94ce 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "@evilmartians/lefthook": "1.2.2", "@react-native-community/eslint-config": "3.2.0", "@release-it/conventional-changelog": "5.0.0", + "@testing-library/jest-native": "^5.4.3", "@testing-library/react-native": "12.1.2", "@types/color": "^3.0.3", "@types/jest": "29.5.2", @@ -104,6 +105,7 @@ "modulePaths": [ "/src" ], + "setupFilesAfterEnv": ["./jest-setup.ts"], "transformIgnorePatterns": [ "node_modules/(?!(@react-native|react-native|react-native-vector-icons))" ] diff --git a/src/components/button/button.spec.tsx b/src/components/button/button.spec.tsx index c130e86..46687c2 100644 --- a/src/components/button/button.spec.tsx +++ b/src/components/button/button.spec.tsx @@ -6,7 +6,8 @@ import { } from '@testing-library/react-native'; import React from 'react'; import { Button } from './button.component'; -import { ActivityIndicator } from 'react-native'; +import { ActivityIndicator, View } from 'react-native'; +import { defaultTheme } from '../../theme/theme.default'; afterEach(cleanup); @@ -19,14 +20,12 @@ describe('Button component', () => { ).toBeTruthy(); }); - it('should button onPress trigger event', () => { + it('should pressing trigger event', () => { const onPressMock = jest.fn(); - const { getByText } = render( - - ); + render(); - const button = getByText('Click Me'); + const button = screen.getByText('Click Me'); fireEvent.press(button); @@ -36,7 +35,7 @@ describe('Button component', () => { it('should be disabled when isDisabled is true', () => { const onPressMock = jest.fn(); - const { getByText } = render( + render( @@ -44,7 +43,7 @@ describe('Button component', () => { expect(onPressMock).not.toHaveBeenCalled(); - const button = getByText('Click Me'); + const button = screen.getByText('Click Me'); fireEvent.press(button); @@ -52,10 +51,56 @@ describe('Button component', () => { }); it('should render ActivityIndicator component if loading', () => { - const { UNSAFE_getByType } = render( + ); + + const text = screen.getByText('This is the button'); + + expect(text).toBeVisible(); + expect(text).toHaveProp('style'); + expect(text.props.style).toHaveProperty('color'); + expect(text.props.style.color).toEqual('black'); + }); }); diff --git a/src/theme/theme.service.ts b/src/theme/theme.service.ts index 078590c..12a9f4f 100644 --- a/src/theme/theme.service.ts +++ b/src/theme/theme.service.ts @@ -134,8 +134,8 @@ export const getThemeColor = ( themeColors.hasOwnProperty(value) && typeof themeColors[value] !== 'undefined' ) { - const colorValue: string | String = themeColors[value] as string; - return colorValue as string; + const colorValue = themeColors[value]; + return colorValue[500]; } let colorValue: string | String = 'transparent'; diff --git a/tsconfig.json b/tsconfig.json index 2c488c4..285fbc1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,7 +22,7 @@ "skipLibCheck": true, "strict": true, "target": "esnext", - "types": ["react-native", "jest"] + "types": ["react-native", "jest", "@testing-library/jest-native"] }, "include": ["src"], "exclude": ["./**/*.spec.ts", "./**/*.spec.tsx"] diff --git a/yarn.lock b/yarn.lock index 35cdeec..b840e6c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2243,6 +2243,17 @@ dependencies: defer-to-connect "^2.0.1" +"@testing-library/jest-native@^5.4.3": + version "5.4.3" + resolved "https://registry.yarnpkg.com/@testing-library/jest-native/-/jest-native-5.4.3.tgz#9334c68eaf45db9eb20d0876728cc5d7fc2c3ea2" + integrity sha512-/sSDGaOuE+PJ1Z9Kp4u7PQScSVVXGud59I/qsBFFJvIbcn4P6yYw6cBnBmbPF+X9aRIsTJRDl6gzw5ZkJNm66w== + 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" + "@testing-library/react-native@12.1.2": version "12.1.2" resolved "https://registry.yarnpkg.com/@testing-library/react-native/-/react-native-12.1.2.tgz#1935affe1106aeddf0087dff31a6d7414917c098"