Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests to project #11

Merged
merged 2 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"lint": "eslint --ext .js,.jsx,.ts,.tsx"
"lint": "eslint --ext .js,.jsx,.ts,.tsx",
"test": "jest"
},
"dependencies": {
"@react-native/metro-config": "^0.73.3",
Expand All @@ -22,6 +23,8 @@
"devDependencies": {
"@babel/core": "^7.20.0",
"@expo/webpack-config": "^19.0.0",
"@testing-library/react-native": "^12.4.3",
"@types/jest": "^29.5.11",
"@types/react": "~18.2.14",
"eslint": "^8.54.0",
"eslint-config-universe": "^12.0.0",
Expand All @@ -30,10 +33,15 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-native": "^4.1.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"jest": "^29.7.0",
"prettier": "^3.1.0",
"react-dom": "18.2.0",
"react-native-web": "~0.19.6",
"react-test-renderer": "^18.2.0",
"typescript": "^5.1.3"
},
"jest": {
"preset": "@testing-library/react-native"
},
"private": true
}
Empty file removed src/components/.placeholder
Empty file.
20 changes: 20 additions & 0 deletions src/components/Button/PrimaryButton.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { fireEvent, render, screen } from '@testing-library/react-native';

import PrimaryButton from './PrimaryButton';

const onPress = jest.fn();

describe('PrimaryButton component tests', () => {
it('properly renders button with provided title', () => {
render(<PrimaryButton title="test" onPress={onPress} />);

expect(screen.getByText('test')).toBeDefined();
});
it('calls provieded onPress method', () => {
render(<PrimaryButton title="test" onPress={onPress} />);

fireEvent(screen.getByText('test'), 'press');

expect(onPress).toHaveBeenCalledTimes(1);
});
});
1 change: 1 addition & 0 deletions src/components/Button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as PrimaryButton } from './PrimaryButton';
Loading