Skip to content

Instantly share code, notes, and snippets.

View nelsonfncosta's full-sized avatar
:shipit:
burnit

Nélson Costa nelsonfncosta

:shipit:
burnit
View GitHub Profile
@nelsonfncosta
nelsonfncosta / drag-util.js
Created May 18, 2021 09:44
Make an element Draggable !
export function dragElement(elmnt, dragElement = elmnt) {
let pos1 = 0;
let pos2 = 0;
let pos3 = 0;
let pos4 = 0;
dragElement.onmousedown = dragMouseDown;
function dragMouseDown(e) {
e = e || window.event;
@nelsonfncosta
nelsonfncosta / act-warning.svg
Created May 18, 2021 15:13
Visual way how to explain the act warning from react testing library
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nelsonfncosta
nelsonfncosta / hast-tag-pyramid.js
Last active May 27, 2021 00:16
hast-tag-pyramid.js
let size = prompt("size?");
for(let i=1; i<=size; i++) console.log("#".repeat(i));
let size = prompt("size?")
for(let i=1; i<= size; i++){
let buffer = ' '.repeat(size-i)
let side = '#'.repeat(i-1)
console.log(`${buffer}${side} ${side}${buffer}`);
}
@nelsonfncosta
nelsonfncosta / test.js
Created September 3, 2021 08:20
async promises test
import React from 'react'
import Dropzone from 'react-dropzone'
import { act, fireEvent, render, waitFor } from '@testing-library/react'
test('invoke onDragEnter when dragenter event occurs', async () => {
const file = new File([
JSON.stringify({ping: true})
], 'ping.json', { type: 'application/json' })
const data = mockData([file])
const onDragEnter = jest.fn()
const loadImage = src =>
new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => resolve(img);
img.onerror = reject;
img.src = src;
});