This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)[] |