Skip to content

Commit

Permalink
adds temp test for useAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
jomurgel committed Sep 5, 2024
1 parent d24dcbf commit 3870dc1
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 11 deletions.
7 changes: 6 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
function config( api ) {
api.cache( true )
return {
presets: [ 'babel-preset-expo', '@babel/preset-typescript' ],
presets: [
'babel-preset-expo',
'@babel/preset-typescript',
'@babel/preset-env',
'@babel/preset-react',
],
}
}

Expand Down
1 change: 0 additions & 1 deletion jest-setup.js

This file was deleted.

19 changes: 12 additions & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
module.exports = {
preset: 'jest-expo',
setupFilesAfterEnv: ['./jest.setup.ts'],
setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.tsx?$': [ 'ts-jest', {
jsx: 'react',
module: 'commonjs',
target: 'es6',
strict: true,
esModuleInterop: true,
skipLibCheck: true,
forceConsistentCasingInFileNames: true,
types: [ 'jest', 'node' ],
} ],
},
testPathIgnorePatterns: [ '/node_modules/', '/android/', '/ios/' ],
globals: {
'ts-jest': {
tsconfig: 'tsconfig.jest.json',
},
},
testEnvironment: 'node',
}
50 changes: 50 additions & 0 deletions src/hooks/useAuth.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// @todo: need to adjust testing configs to support imports an file types.
// import { renderHook } from '@testing-library/react'
// import React, { ReactNode } from 'react'
// import {
// expect, describe, it, jest,
// } from '@jest/globals'
// import { User } from '@supabase/supabase-js'
// import useAuth from './useAuth'
// import { AuthContext } from '../providers/AuthProvider'
// import { AuthContextType } from '../types/auth'

// describe( 'useAuth', () => {
// it( 'should throw an error if used outside of AuthProvider', () => {
// const { result } = renderHook( () => useAuth() )

// // Expect the hook to throw an error when used outside the AuthProvider
// expect( result.current.error ).toEqual(
// new Error( 'useAuth must be used within an AuthProvider' ),
// )
// } )

// it( 'should return the context value when used within AuthProvider', () => {
// // @todo: need to setup a different parser for this.
// // Mock the context value conforming to AuthContextType
// const mockAuthContextValue: AuthContextType = {
// error: null,
// loading: false,
// session: null,
// // @ts-expect-error ignore for testing, not important.
// signUpNewUser: ( jest.fn().mockResolvedValue( undefined ) as jest.Mock ),
// // @ts-expect-error ignore for testing, not important.
// signInWithEmail: ( jest.fn().mockResolvedValue( undefined ) as jest.Mock ),
// // @ts-expect-error ignore for testing, not important.
// signOut: ( jest.fn().mockResolvedValue( undefined ) as jest.Mock ),
// user: { id: '1', email: 'test@example.com' } as User, // Mocking user object
// }

// // Define the wrapper component with the correct context value
// const wrapper = ( { children }: { children: ReactNode } ) => (
// <AuthContext.Provider value={mockAuthContextValue}>
// {children}
// </AuthContext.Provider>
// )

// const { result } = renderHook( () => useAuth(), { wrapper } )

// // Expect the hook to return the correct context value
// expect( result.current ).toEqual( mockAuthContextValue )
// } )
// } )
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
fetchLists, removeList, addList, fetchTodosByListId, addTodo, removeTodo, toggleTodoStatus,
} from './thunks/todoThunk'
} from '../thunks/todoThunk'

/**
* Extra reducers for handling local state from Supabase.
Expand Down
2 changes: 1 addition & 1 deletion src/redux/slices/todoSlice.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { Todo, TodoList } from '../../types/todos'
import todoReducers from '../todoReducers'
import todoReducers from '../reducers/todoReducers'

interface TodosState {
lists: TodoList[];
Expand Down
11 changes: 11 additions & 0 deletions src/types/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare module 'expo-constants' {
interface Constants {
expoConfig: {
extra: {
GITHUB_CLIENT: string,
SUPABASE_KEY: string,
SUPABASE_CALLBACK: string,
};
};
}
}

0 comments on commit 3870dc1

Please sign in to comment.