Skip to content

Instantly share code, notes, and snippets.

View fernandodof's full-sized avatar
🎯
Focusing

Fernando Ferreira fernandodof

🎯
Focusing
View GitHub Profile
<Tabs>
<TabPane title="Basic">
<div>Basic</div>
</TabPane>
<TabPane title="Standard">
<div>Standard</div>
</TabPane>
<TabPane title="Premium">
<div>Premium</div>
</TabPane>
@fernandodof
fernandodof / tabs.jsx
Last active October 9, 2021 22:13
tabs
import React, { ReactElement, useState } from 'react';
import styles from './tabs.module.css';
import TabTitle, { Props as TabTitleProps } from './TabTitle';
type Props = {
children: ReactElement<TabTitleProps>[];
preSelectedTabIndex?: number;
};
import React, { ReactElement } from 'react';
type Props = {
title: string;
children: ReactElement | ReactElement[];
};
const TabPane = ({ children }: Props): JSX.Element => <div>{children}</div>;
export default TabPane;
import React, { ReactElement } from 'react';
type Props = {
title: string;
children: ReactElement | ReactElement[];
};
const TabPane = ({ children }: Props): JSX.Element => <div>{children}</div>;
export default TabPane;
@fernandodof
fernandodof / tab-title.jsx
Last active October 9, 2021 22:11
React tabs
import React, { useCallback } from 'react';
import styles from './tabTitle.module.css';
export type Props = {
title: string;
index: number;
setSelectedTab: (index: number) => void;
isActive?: boolean;
};
describe('When the promise is rejected', () => {
beforeEach(async () => {
fetch.mockRejectedValueOnce(new Error("I'm a teapot"));
averagePrice = await getPricesLastDays(7);
});
it('Then the fuction should return null', () => {
expect(averagePrice).toEqual(null);
});
});
const MOCK_PRICES = [50, 47, 53, 50, 49, 51, 52];
const MOCK_AVERAGE = 50.29;
global.fetch = jest.fn(() => Promise.resolve({
json: () => Promise.resolve(MOCK_PRICES)
}));
describe('Gold prices', () => {
let averagePrice;
const MOCK_PRICES = [50, 47, 53, 50, 49, 51, 52];
global.fetch = jest.fn(() => Promise.resolve({
json: () => Promise.resolve(MOCK_PRICES)
}));
const result = await fetch(`https://api.gold/price?days=${days}`);
const prices = await result.json();
describe('When the average price is called for 7 days', () => {
beforeEach(async () => {
averagePrice = await getPricesLastDays(7);
});
it('Then the correct average should be returned', () => {
expect(averagePrice).toEqual({ average: MOCK_AVERAGE });
});
});