Skip to content

Instantly share code, notes, and snippets.

View enzzoperez's full-sized avatar
🐙
Stay Alive ||-//

random17 enzzoperez

🐙
Stay Alive ||-//
View GitHub Profile
it('testing error in request', async () => {
const mock = new MockAdapter(axios);
mock.onGet().reply(404, {data: []}); //or mock.onGet().networkError();
const {result, waitForNextUpdate} = renderHook(
({url}) => useRemoteData({url}),
{
initialProps: {
url: '',
it('testing success get request', async () => {
const mock = new MockAdapter(axios);
mock.onGet().reply(200, {data: []});
const {result, waitForNextUpdate} = renderHook(
({url}) => useRemoteData({url}),
{
initialProps: {
url: '',
describe('Testing uses cases for async hook', () => {
it('', async () => {
const mock = new MockAdapter(axios);
mock.onGet().reply(200, {data: []});
const {result, waitForNextUpdate} = renderHook(
({url}) => useRemoteData({url}),
{
initialProps: {
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
describe('Testing uses cases for async hook', () => {
it('testing success get request', async () => {
const mock = new MockAdapter(axios);
});
});
export default {
//the keys has to be the same that in the .env file
API_URL: 'http://mock',
};
//IMPORTS
interface ILogos {
light: string;
dark: string;
}
export interface HomeResponse {
id: string;
name: string;
import {useState, useEffect} from 'react';
import axios, {AxiosError, AxiosRequestConfig} from 'axios';
import Config from 'react-native-config'; //lib used for env vars
//set the base url for axios
axios.defaults.baseURL = Config.API_URL;
const useRemoteData = <T>({url, method, headers, data}: AxiosRequestConfig) => {
const [response, setResponse] = useState<T>();
const [error, setError] = useState<AxiosError>();
import React from 'react';
import {
View,
} from 'react-native';
import {useRemoteData} from 'hooks/useRemoteData'; //or '@hooks/useRemoteData'
import {Button} from 'components/button'; //or '@components/button'
const Home: React.FC = () => {
return (
<View >
plugins: [
[
'module-resolver',
{
root: ['./src'],
extensions: ['.ios.js', '.android.js', '.js', '.ts', '.tsx', '.json'],
alias: {
'@components': './src/components',
'@hooks': './src/hooks/',
},
"baseUrl": ".",
"paths": {
"*": ["src/*"],
"@components/*": ["src/components/*"],
"@hooks/*": ["src/hooks/*"],
},