App.test.tsx
Satyam
plain_text
a year ago
2.1 kB
9
Indexable
import * as React from 'react';
import {fireEvent, render, waitFor} from '@testing-library/react-native';
import App from '../App';
import testIdConstant from '../testId.constant';
import Snackbar from 'react-native-snackbar';
import MockAdapter from 'axios-mock-adapter';
import axios from 'axios';
jest.mock('react-native-snackbar');
const mock = new MockAdapter(axios);
beforeEach(() => {
mock.reset();
});
describe('Login Screen', () => {
it('should display an error message when the input is empty', async () => {
const {getByTestId, queryByText, getByText} = render(<App />);
const emailInput = getByTestId(testIdConstant.emailInput);
const passInput = getByTestId(testIdConstant.passwordInput);
const btnLogin = getByTestId(testIdConstant.loginBtn);
fireEvent.changeText(emailInput, '');
fireEvent.changeText(passInput, '');
fireEvent.press(btnLogin);
expect(getByText('Please enter Email')).toBeTruthy();
expect(getByText('Please enter Password')).toBeTruthy();
});
it('should display an error message when the email is invalid', async () => {
const {getByTestId, queryByText, getByText} = render(<App />);
const emailInput = getByTestId(testIdConstant.emailInput);
const btnLogin = getByTestId(testIdConstant.loginBtn);
fireEvent.changeText(emailInput, 'invalidemail');
fireEvent.press(btnLogin);
expect(getByText('Please enter valid Email')).toBeTruthy();
});
it('should login with correct credentials', async () => {
const {getByTestId, queryByText, getByText} = render(<App />);
const emailInput = getByTestId(testIdConstant.emailInput);
const passInput = getByTestId(testIdConstant.passwordInput);
const btnLogin = getByTestId(testIdConstant.loginBtn);
fireEvent.changeText(emailInput, 'satyam@yopmail.com');
fireEvent.changeText(passInput, '123456');
fireEvent.press(btnLogin);
expect(Snackbar.show).toHaveBeenCalledWith({
text: 'Success',
duration: Snackbar.LENGTH_SHORT,
backgroundColor: '#000',
marginBottom: 10,
});
});
});
Editor is loading...
Leave a Comment