Skip to content

Instantly share code, notes, and snippets.

@dejanvasic85
dejanvasic85 / profile.spec.js
Created August 7, 2020 11:38
Cypress Example
/// <reference types="cypress" />
context('Invite Client', () => {
after(() => {
cy.logout().then(() => {
cy.url().should('contains', Cypress.env('base_login_url'));
});
});
it('should display the profile page with confirmed email', () => {
@dejanvasic85
dejanvasic85 / httpClient.ts
Created September 23, 2020 00:28
Axios Http Client with Logging
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
import tracingLogger from '../../logging/tracingLogger';
interface RequestConfig extends AxiosRequestConfig {
metadata: {
startTime: number;
};
}
const createHttpClient = (baseURL: string, defaultHeaders: any = {}): AxiosInstance => {
@dejanvasic85
dejanvasic85 / chat.tsx
Last active January 8, 2021 11:37
Chat.tsx
import React, { Fragment, useEffect, useRef } from 'react';
import { useQuery, useMutation } from '@apollo/client';
import { List, Typography } from 'antd';
import PageLoader from '../PageLoader/PageLoader';
import ChatInput from './components/ChatInput';
import ChatComment from './components/ChatComment';
import { ADD_MESSAGE, CHAT_ROOM, COMMENTS_SUBSCRIPTION } from './Chat.graphql';
import { AddResponse, ChatRequest, ChatResponse, MessageInput, NewMessage, Props } from './Chat.types';
import styles from './Chat.less';
@dejanvasic85
dejanvasic85 / ArrayToType.tsx
Last active March 17, 2022 22:29
Typescript string array to Type
export const layout = ['inline', 'stacked'] as const;
export type Layout = typeof layout[number];
// Then it can be used in React props
interface Props {
layout: Layout;
}
const Component = ({ layout }: Props) => (
@dejanvasic85
dejanvasic85 / compose.ts
Created July 2, 2023 04:01
Composing promises in typescript
// Here's the original article for function composition and piping: https://blog.logrocket.com/how-to-create-compose-function-typescript/
interface Context {
user: string;
content: string;
}
// And this is how to implement the same method using Promises:
const compose = <T>(fn1: (a: T) => Promise<T>, ...fns: Array<(a: T) => Promise<T>>) =>
fns.reduce((prevFn, nextFn) => async (value) => await prevFn(value).then(nextFn), fn1);