Skip to content

Instantly share code, notes, and snippets.

View tidusia's full-sized avatar

Thibaud Duthoit tidusia

View GitHub Profile
@tidusia
tidusia / snapshot-overkill-appbar.js
Created January 30, 2018 20:20
Medium Snapshot Overkill - Simple AppBar component
import React from 'react';
import PropTypes from 'prop-types';
const AppBar = ({
children,
className,
iconElementLeft,
iconElementRight,
title,
titleStyle,
@tidusia
tidusia / snapshot-overkill-simple-snapshot.js
Created January 30, 2018 20:25
Medium Snapshot overkill - Simple AppBar snapshot
import React from 'react';
import ShallowRenderer from 'react-test-renderer/shallow';
import AppBar from '../';
describe('<AppBar />', () => {
const renderer = new ShallowRenderer();
it('should match snapshot without props', () => {
renderer.render(<AppBar />);
@tidusia
tidusia / how-works-jest.js
Last active November 21, 2018 08:45
redux-comment-tester-ses-reducers-simplement (how work jest)
describe("here name which function or feature you are testing", () => {
it("here explain what specific part of the feature should do", () => {
expect(1 + 1).toBe(2);
});
});
@tidusia
tidusia / index.js
Created November 21, 2018 09:19
redux-comment-tester-ses-reducers-simplement (should return the initial state FAIL)
export const ACTIONS = {
GET_USER_REQUEST: "GET_USER_REQUEST",
GET_USER_SUCCESS: "GET_USER_SUCCESS",
GET_USER_FAILURE: "GET_USER_FAILURE"
};
export const initialState = {
isFetching: false,
errors: [],
profile: {}

React new project

Prettier

  • npm i -D prettier
  • package.json scripts: "format": "prettier \"src/**/*.{js,html}\" --write"
  • touch .prettierrc avec : { "trailingComma": "es5" }

JetBrains: Preferences | Languages & Frameworks | JavaScript | Prettier

  • Enable the option Run on save for files.
test("should render an empty firstname input", () => {
const props = Default.args as Props;
const { getByLabelText } = render(<Default {...props} />);
const input = getByLabelText("Firstname") as HTMLInputElement;
expect(input).toBeInTheDocument();
expect(input.value).toBe("");
});
import React from "react";
import { render } from "@testing-library/react";
import { Props } from ".";
import { Default } from "./index.stories";
test("should render the title", () => {
const props = Default.args as Props;
const { getByText } = render(<Default {...props} />);
const actual = getByText(props.title);
expect(actual).toBeInTheDocument();
import React, { FunctionComponent } from "react";
type Props = React.SVGProps<any> & {
className: string;
title?: string;
};
const Download: FunctionComponent<Props> = ({
className,
title,
import React from "react";
import { render } from "@testing-library/react";
import { Props } from ".";
import { Default } from "./index.stories";
describe("COMPONENT_NAME", () => {
describe("Default", () => {
const props = Default.args as Props;
test("should match snapshot", () => {
import { axe } from "jest-axe";
test("should be accessible", async () => {
const { container } = render(<Component />);
expect(await axe(container)).toHaveNoViolations();
});