Skip to content

Instantly share code, notes, and snippets.

View darde's full-sized avatar

Pablo Rodrigo Darde darde

View GitHub Profile
@darde
darde / default.json
Created August 5, 2018 16:46
react-i18next-example/src/components/Home/locales/default.json
{
"pt-BR": {
"title": "Faróis",
"content": "Conheça os mais lindos faróis do mundo.",
"figure": {
"alt": "Foto de farol"
}
}
}
@darde
darde / default.en.json
Created August 5, 2018 16:50
react-i18next-example/src/components/Home/locales/default.en.json
{
"en": {
"title": "Lighthouses",
"content": "Know the most beautiful lighthouses of the world.",
"figure": {
"alt": "Lighthouse picture"
}
}
}
@darde
darde / index.js
Last active August 7, 2018 19:20
react-i18next-example/src/i18n/index.js
import i18n from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import { pt, en } from './locales';
const options = {
interpolation: {
escapeValue: false, // not needed for react!!
},
debug: true,
@darde
darde / App.js
Created August 7, 2018 18:50
react-i18next-example/src/App.js
import React from 'react';
import AppProvider from './components/context/AppProvider';
import { I18nextProvider } from 'react-i18next';
import i18n from './i18n';
import Router from './components/Router';
import Toolbar from './components/Toolbar';
import './styles/styles.css';
const App = () => (
<div className='wrapper'>
@darde
darde / index.jsx
Created August 7, 2018 18:52
react-i18next-example/src/components/Home/index.jsx
import React from 'react';
import photo from './photo.jpg';
const Home = () => (
<div className='preview'>
<h1>Lighthouses</h1>
<div className="cover">
<figure className='center'>
<img src={photo} alt="Lighthouse picture"/>
</figure>
@darde
darde / index.jsx
Created August 7, 2018 18:53
react-i18next-example/src/components/Home/index.jsx
import React from 'react';
import { translate } from 'react-i18next';
import photo from './photo.jpg';
const Home = ({ t }) => (
<div className='preview'>
<h1>{t('home.title')}</h1>
<div>
<figure className='center'>
<img src={photo} alt={t('home.figure.alt')} />
@darde
darde / App.js
Last active February 22, 2020 23:41
Medium store - Testing asynchronous code with Jest and Testing Library React - src/App.js - part 1
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import fetchPosts from './services/fetchPosts';
function App() {
const [posts, setPosts] = useState([]);
useEffect(() => {
let mounted = true;
@darde
darde / fetchPosts.js
Last active February 22, 2020 23:04
Medium store - Testing asynchronous code with Jest and Testing Library React - src/services/fetchPosts.js
import axios from 'axios';
const BASE_URL = 'https://jsonplaceholder.typicode.com/posts';
export default async () => {
const response = await axios.get(BASE_URL);
return response.data;
}
@darde
darde / axios.js
Created February 22, 2020 22:46
Medium store - Testing asynchronous code with Jest and Testing Library React - src/__mocks__/axios.js
export default {
get: jest.fn(() => Promise.resolve({
data: [
{
id: 1,
title: 'This is a tech post',
},
{
id: 2,
title: 'Post about testing code',
@darde
darde / fetchPosts.test.js
Created February 22, 2020 22:50
Medium store - Testing asynchronous code with Jest and Testing Library React - src/services/fetchPosts.test.js
import fetchPosts from './fetchPosts';
import mockedAxios from 'axios';
describe('fetchPosts', () => {
it('fetch the posts', async () => {
const posts = await fetchPosts();
const expectedResponse = [
{
id: 1,