Skip to content

Commit

Permalink
feat: create test for button component
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaladin committed Dec 19, 2022
1 parent bf7289c commit 1e9ce8d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/__tests__/button.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import React from 'react';
import { cleanup, render } from '@testing-library/react-native';
import { cleanup, render, fireEvent } from '@testing-library/react-native';
import { Button } from '../components/Button';

afterEach(cleanup);

describe('App', () => {
describe('Button component', () => {
it('should find the button component via testId', () => {
const testIdName = 'testButtonId';

const { getByTestId } = render(<Button />);

const foundButton = getByTestId(testIdName);

expect(foundButton).toBeTruthy();
});

it('should call onPress function when pressed', () => {
const testIdName = 'testButtonId';
const onPress = jest.fn();
const { getByTestId } = render(<Button onPress={onPress} />);
fireEvent.press(getByTestId(testIdName));
expect(onPress).toHaveBeenCalledTimes(1);
});
});

0 comments on commit 1e9ce8d

Please sign in to comment.