-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsettingsbar.test.tsx
More file actions
32 lines (26 loc) · 1.11 KB
/
settingsbar.test.tsx
File metadata and controls
32 lines (26 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react-native';
// Mock useAuth
jest.mock('../context/Auth', () => ({ useAuth: jest.fn() }));
const { useAuth } = require('../context/Auth') as { useAuth: jest.Mock };
// Mock useNavigation
const mockNavigate = jest.fn();
jest.mock('@react-navigation/native', () => {
const actual = jest.requireActual('@react-navigation/native');
return { ...actual, useNavigation: () => ({ navigate: mockNavigate }) };
});
beforeEach(() => { useAuth.mockReset(); mockNavigate.mockReset(); });
test('Shows Unsigned in: Sign In/Up Button', () => {
useAuth.mockReturnValue({ user: null, signOut: jest.fn() });
const Comp = require('../components/SettingsBar').default;
render(<Comp />);
});
test('Login: Email and Sign out', () => {
const signOut = jest.fn();
useAuth.mockReturnValue({ user: { email: 'me@x' }, signOut });
const Comp = require('../components/SettingsBar').default;
render(<Comp />);
expect(screen.getByText('me@x')).toBeTruthy();
fireEvent.press(screen.getByText('Sign out'));
expect(signOut).toHaveBeenCalled();
});