Skip to content

Instantly share code, notes, and snippets.

View paularmstrong's full-sized avatar
🐈‍⬛
Codes with cats

Paul Armstrong paularmstrong

🐈‍⬛
Codes with cats
View GitHub Profile
export default function(target) {
const originalMethods = {
UNSAFE_componentWillMount: target.prototype.UNSAFE_componentWillMount || noop,
componentDidMount: target.prototype.componentDidMount || noop,
UNSAFE_componentWillUpdate: target.prototype.UNSAFE_componentWillUpdate || noop,
componentDidUpdate: target.prototype.componentDidUpdate || noop,
componentWillUnmount: target.prototype.componentWillUnmount || noop
};
/**
* Copyright (c) 2019 Paul Armstrong
*/
import React from 'react';
import { render } from 'react-testing-library';
import Tooltip from '../Tooltip';
import { Dimensions, MeasureOnSuccessCallback, View } from 'react-native';
describe('Tooltip', () => {
let viewRef;
/**
* Copyright (c) 2019 Paul Armstrong
*/
import * as Theme from '../theme';
import React from 'react';
import { StyleProp, StyleSheet, TouchableOpacity, TouchableOpacityProps, View, ViewStyle } from 'react-native';
interface Props {
children: React.ReactElement;
disabled?: boolean;
export default function(target) {
const originalMethods = {
UNSAFE_componentWillMount: target.prototype.UNSAFE_componentWillMount || noop,
componentDidMount: target.prototype.componentDidMount || noop,
UNSAFE_componentWillUpdate: target.prototype.UNSAFE_componentWillUpdate || noop,
componentDidUpdate: target.prototype.componentDidUpdate || noop,
componentWillUnmount: target.prototype.componentWillUnmount || noop
};
target.prototype.UNSAFE_componentWillMount = function(...args) {
@paularmstrong
paularmstrong / foo.test.js
Last active March 29, 2018 03:00
Mocha test runner with Require.js
define(['modules/foo'], function (foo) {
describe('test foo', function () {
// ...
});
});

Convert Mocha and Chai to Jest

$ jscodeshift <path> -t assert-to-expect.js
$ jscodeshift <path> -t mocha-to-jest.js
const HeartIcon = (props) => React.createElement('svg', {
...props,
dangerouslySetInnerHTML: { __html: '<g><path d="M38.723 12c-7.187 0-11.16 7.306-11.723 8.131C26.437 19.306 22.504 12 15.277 12 8.791 12 3.533 18.163 3.533 24.647 3.533 39.964 21.891 55.907 27 56c5.109-.093 23.467-16.036 23.467-31.353C50.467 18.163 45.209 12 38.723 12z"></path></g>' },
viewBox: '0 0 54 72'
});
@paularmstrong
paularmstrong / memorySizeOfObject.js
Created March 16, 2017 17:03
calculate memory size of javascript object, it is not a accurate value!
function memorySizeOf(obj) {
var bytes = 0;
function sizeOf(obj) {
if(obj !== null && obj !== undefined) {
switch(typeof obj) {
case 'number':
bytes += 8;
break;
case 'string':
@paularmstrong
paularmstrong / memorySizeOfObject.js
Created March 16, 2017 17:03
calculate memory size of javascript object, it is not a accurate value!
function memorySizeOf(obj) {
var bytes = 0;
function sizeOf(obj) {
if(obj !== null && obj !== undefined) {
switch(typeof obj) {
case 'number':
bytes += 8;
break;
case 'string':
const FetchStatus = {
FAILED: 'failed',
LOADED: 'loaded',
LOADING: 'loading',
NONE: 'none'
};
class LoadingRenderer extends React.Component {
static propTypes = {
fetchStatus: React.PropTypes.oneOf(Object.values(FetchStatus)).isRequired,