Skip to content

Instantly share code, notes, and snippets.

View skellock's full-sized avatar

Steve Kellock skellock

View GitHub Profile
import mockery from ‘mockery’
// inject __DEV__
global.__DEV__ = true
// We enable mockery and leave it on.
mockery.enable()
// Silence mockery's warnings as we'll opt-in to mocks instead
mockery.warnOnUnregistered(false)
import mockery from ‘mockery’
// inject __DEV__
global.__DEV__ = true
// We enable mockery and leave it on.
mockery.enable()
// Silence mockery's warnings as we'll opt-in to mocks instead
mockery.warnOnUnregistered(false)
mockery.registerMock('react-native-router-flux', {
Actions: {
login: () => {},
video: () => {}
}
})
import React, { Component, PropTypes } from 'react'
import { TouchableOpacity, Text } from 'react-native'
// Your average run of the mill Button component.
export default class Button extends Component {
render () {
return (
<TouchableOpacity onPress={this.props.onPress}>
<Text>{this.props.text}</Text>
</TouchableOpacity>
import test from 'ava'
import React from 'react'
import Button from '../Button'
import { shallow } from 'enzyme'
test('component structure', t => {
const wrapper = shallow(<Button onPress={() => {}} text='hi' />)
t.is(wrapper.name(), 'TouchableOpacity') // root component
t.is(wrapper.children().length, 1) // has 1 child
test('onPress', t => {
let i = 0
const onPress = () => i++
const wrapper = shallow(<Button onPress={onPress} text='hi' />)
t.is(wrapper.prop('onPress'), onPress) // uses the right handler
t.is(i, 0)
wrapper.simulate('press')
t.is(i, 1)
})
/**
* --------------------
* ReactotronSlowlog.js
* --------------------
*
* A Reactotron plugin for react-native-slowlog by Dotan J. Nahum.
*
* https://github.com/jondot/react-native-slowlog
*
* --- PRE-REQUESTS ---
api.post('/upload', data, {
onUploadProgress: progressEvent => {
const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
// don't be spammy when we log
if (percentComplete % 10 === 0) {
console.tron.log(``)
}
}
})
// Source: https://github.com/szwacz/fs-jetpack/blob/master/lib/read.js#L22-L32
const fromJsonDate = value => {
const reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*))(?:Z|(\+|-)([\d|:]*))?$/
if (typeof value === 'string') {
if (reISO.exec(value)) {
return new Date(value)
}
}
return value
}
@skellock
skellock / extensions.json
Last active November 5, 2017 17:58
VSCode's Settings - Syncing
[
{
"name": "node-debug2",
"publisher": "ms-vscode",
"version": "1.18.4",
"id": "ms-vscode.node-debug2",
"__metadata": {
"id": "36d19e17-7569-4841-a001-947eb18602b2",
"publisherId": "5f5636e7-69ed-4afe-b5d6-8d231fb3d3ee",
"publisherDisplayName": "Microsoft"