Skip to content

Instantly share code, notes, and snippets.

@shahab65
shahab65 / cypress-cheatsheet.md
Last active April 5, 2019 17:41
learning cypress

cypress

should

cy.url().should('include', 'login')
cy.get('input[name=email]').type(email);
test("returns undefined by default", () => {
  const mock = jest.fn();

  let result = mock("foo");

  expect(result).toBeUndefined();
  expect(mock).toHaveBeenCalled();
  expect(mock).toHaveBeenCalledTimes(1);
 expect(mock).toHaveBeenCalledWith("foo");

unstyled list:

    list-style-type: none;
yarn add history
import createHistory from 'history/createBrowserHistory';
export const history = createHistory();
<Router history={history}>

above code has warning so I changed it to this:

import { createBrowserHistory } from 'history';
export const history = createBrowserHistory();
@shahab65
shahab65 / curl.md
Last active July 24, 2019 14:37
curl commands
curl https://0ca6yach5d.execute-api.us-east-1.amazonaws.com/development/account/api/v1/users/ --header "Authorization: Bearer my-token"
@shahab65
shahab65 / array.md
Last active October 14, 2020 03:55

remove from array in returning removed item:

const removeUser = id => {
  const index = users.findIndex((user) => user.id === id)
  
  if (index !== -1) {
    return users.splice(index, 1)[0]
    }
    }
//import {Field, Form, Formik} from "formik";
// import * as Yup from "yup";

      <Formik
        enableReinitialize
        initialValues={calculatedFormInitialValues}
        validate={values => {
            let errors = {};
 if (values.responsible_user === "" &amp;&amp; values.responsible_department === "") {

If we have multiple promises we could use Promise.all with await

async function asyncFunc() {
  const response = await Promise.all([
    axios.get("/some_url_endpoint"),
    axios.get("/some_url_endpoint")
  ]);
  ...
}
function getRandomInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max-min)) + min
  }

how to put element in vertical center of parent?

<div class={"parent"}>
  ...
  <div class={"child"}>
    ...
  </div>
</div>

vertical center: