Skip to content

Instantly share code, notes, and snippets.

View LissetteIbnz's full-sized avatar
:electron:
Focusing

Sara Lissette LissetteIbnz

:electron:
Focusing
View GitHub Profile
@alfonsomunozpomer
alfonsomunozpomer / Fetch.test.js
Created September 28, 2017 12:51
How to test a React component that sets its state in componentDidMount with fetch, and how to mock it, in Jest
// https://github.com/alfonsomunozpomer/react-fetch-mock
import React from 'react'
import fetchMock from 'fetch-mock'
import Enzyme from 'enzyme'
import {shallow, mount, render} from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
Enzyme.configure({ adapter: new Adapter() })
@mitchell-garcia
mitchell-garcia / vuex.d.ts
Created October 25, 2017 13:35
Manually Typed Vuex Typescript Definition
/**
* Static vuex typings copied from ones included in node_modules.
*
* We need to do this in order to get typings for this.$store in components.
* Once this Feature is added, we can remove this + the custom mapping in tsconfig.json
* https://github.com/vuejs/vuex/issues/994
*/
import Vue, { WatchOptions } from 'vue';
type Dictionary<T> = { [key: string]: T };
/**
* TypeScript version of @istarkov's cancellable Promise wrapper.
*
* @see https://github.com/facebook/react/issues/5465#issuecomment-157888325
*/
const makeCancelable = <T>(promise: Promise<T>): { promise: Promise<T>; cancel(): void } => {
let hasCanceled = false;
const wrappedPromise = new Promise<T>((resolve, reject) => {
promise.then(
import { orm } from '@orm';
// Other needed imports and operations...
describe('Block description', () => {
// Type error restoring the mock (mocking strategy #1)...
test('whatever test description.', async (done) => {
// Creating the spyOn...
jest.spyOn(orm.controllers, 'enableUserAccount')
// Mocking the function...
orm.controllers.enableUserAccount = jest
@ivanbtrujillo
ivanbtrujillo / readonly.ts
Last active June 17, 2020 09:40
Avoid mutations using Readonly in Typescript
interface User {
id: number;
name: string;
}
// Objects
We are going to change the name of the user. We will have three functions:
- changeName1 : mutates the object. Bad practice because mutations are a source of bugs hard to find.
@ClickerMonkey
ClickerMonkey / types.ts
Last active August 8, 2024 00:25
Typescript Helper Types
// when T is any|unknown, Y is returned, otherwise N
type IsAnyUnknown<T, Y, N> = unknown extends T ? Y : N;
// when T is never, Y is returned, otherwise N
type IsNever<T, Y = true, N = false> = [T] extends [never] ? Y : N;
// when T is a tuple, Y is returned, otherwise N
// valid tuples = [string], [string, boolean],
// invalid tuples = [], string[], (string | number)[]