Skip to content

Instantly share code, notes, and snippets.

View alpavlove's full-sized avatar

Alexey Pavlov alpavlove

View GitHub Profile
@alpavlove
alpavlove / Button.test.tsx
Created August 18, 2022 13:44
Test React Components library
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Button } from '../src/Button/Button';
describe('Button', () => {
describe('Should be rendered correctly', () => {
test('should be clickable', () => {
const onClick = jest.fn();
render(<Button onClick={onClick}>Click me</Button>);
fireEvent.click(screen.getByText('Click me'));
@alpavlove
alpavlove / Button.test.tsx
Created August 18, 2022 13:31
Test React Components library
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Button } from '../src/Button/Button';
describe('Button', () => {
describe('Should be rendered correctly', () => {
test('disabled', () => {
const { asFragment } = render(
<Button onClick={console.log} isDisabled={true}>
Click me
@alpavlove
alpavlove / Button.test.tsx
Created August 18, 2022 13:29
Test React Components library
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Button } from '../src/Button/Button';
describe('Button', () => {
describe('Should be rendered correctly', () => {
test('disabled', () => {
const { asFragment } = render(
<Button onClick={console.log} isDisabled={true}>
Click me
@alpavlove
alpavlove / Button.test.tsx
Created August 18, 2022 13:20
Test React Components library
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Button } from '../src/Button/Button';
describe('Button', () => {
describe('Should be rendered correctly', () => {
test('success', () => {
const { container } = render(
<Button onClick={console.log} variant="success">
Click me
@alpavlove
alpavlove / Button.test.tsx
Last active August 18, 2022 13:19
Test React Components library
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Button } from '../src/Button/Button';
describe('Button', () => {
describe('Should be rendered correctly', () => {
test('default', () => {
render(<Button onClick={console.log}>Click me</Button>);
const button = screen.getByText('Click me');
expect(button.classList.contains('button-primary')).toBeTruthy();
@alpavlove
alpavlove / Button.test.tsx
Last active August 18, 2022 13:18
Test React Components library
import React from 'react';
describe('Button', () => {
describe('Should be rendered correctly', () => {
test('default', () => {});
// test('success', () => {});
// test('disabled', () => {});
// test('should be clickable', () => {});
// test('should not be clickable if disabled', () => {});
});
@alpavlove
alpavlove / tsdx.config.js
Created July 28, 2022 14:46
Create React Components library
const postcss = require('rollup-plugin-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
module.exports = {
rollup(config, options) {
config.plugins.push(
postcss({
plugins: [
autoprefixer(),
cssnano({
@alpavlove
alpavlove / Button.stories.tsx
Created July 28, 2022 14:33
Create React Components library
import React from 'react'
import { Meta, Story } from '@storybook/react'
import { Button, ButtonProps } from '../src/Button/Button'
const meta: Meta = {
title: 'Welcome',
component: Button,
argTypes: {
children: {
control: {
@alpavlove
alpavlove / Button.css
Last active July 28, 2022 14:25
Create React Components library
.button {
color: #fff;
padding: 0.5rem 2rem;
border: 0;
border-radius: 0.25rem;
}
.button-primary {
background-color: #4747d0;
}
@alpavlove
alpavlove / Button.tsx
Created July 28, 2022 13:24
Create React Components library
import React, { ReactNode } from 'react'
import './Button.css'
export type ButtonProps = {
onClick(): void
children: ReactNode
variant?: 'primary' | 'success'
isDisabled?: boolean
}