Skip to content

Instantly share code, notes, and snippets.

View async-test.js
const { mount, getWrapper } = createTestContext({
fixture: {
component: Users,
fetch: [{
matcher: '/users',
response: ['Mary', 'Jason']
}]
}
});
View yeah right.jsx
const UnrealisticComponent = ({ onReply }) => (
<button onClick={() => onReply('Ja')}>Alles gut?</button>
)
View a taste of the Cosmos Testing API.jsx
import createTestContext from 'react-cosmos-test/enzyme';
import fixture from './logged-in.fixture';
const { mount, getWrapper, get } = createTestContext({ fixture });
beforeEach(mount);
test('welcomes logged in user by name', () => {
expect(getWrapper('.welcome').text()).toContain('Dan');
});
View seriously? I *wish* testing were so easy.jsx
const onReply = jest.fn();
const wrapper = shallow(<UnrealisticComponent onReply={onReply} />)
test('kindly asks if everything is alright', () => {
expect(wrapper.text()).toBe('Alles gut?')
})
test('receives positive response upon click', () => {
wrapper.find('button').simulate('click')
expect(onReply).toHaveBeenCalledWith('Ja')
@skidding
skidding / rename.js
Last active Nov 30, 2017
Rename camelCase files to kebab-files
View rename.js
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const { kebabCase } = require('lodash');
glob
.sync('**/*', { ignore: '**/{coverage,node_modules}/**' })
.forEach(filePath => {
const pathParts = filePath.split('/');
const fileName = pathParts.pop();
@skidding
skidding / test.js
Created May 25, 2017
Enzyme mount() vs shallow() for component context providers
View test.js
import React, { Component, PropTypes } from 'react';
import { shallow, mount } from 'enzyme';
class ContextProvider extends Component {
getChildContext() {
return {
foo: 'bar'
};
}
@skidding
skidding / backdiff.sh
Created Jan 26, 2017
Quickly back up git diff without committing work in progress
View backdiff.sh
git diff HEAD > myprecious.patch
mv myprecious.patch ~/Desktop # auto backed on iCloud
View gist:9b8474a16d01604f5705
index.html
+ var domContainer = document.getElementById('content');
+ var rootComponent = Boards.render(getFixtureContents(), domContainer);
+ Boards.onRouteChange(function(props) {
+ rootComponent = Boards.render(props, domContainer);
+ });
boards.js
@skidding
skidding / gist:5850621
Last active Dec 18, 2015
Calculate percentages of loading time improvement
View gist:5850621
var times = [
// Dashboard
[12.50, 3.41],
// Settings
[12.04, 3.00],
// Mention Stream
[11.90, 3.07],
[11.90, 4.35],
// Signal Stream
[11.81, 2.53],
@skidding
skidding / gist:5850424
Created Jun 24, 2013
Benchmarking the loading time of app.ubervu.com, behind the scenes of the Loading Animation
View gist:5850424
function getTime() {
return new Date().getTime() / 1000;
}
function seconds(time) {
return time.toFixed(2) + 's';
}
// Start counting as soon as the website loads
var startedLoadingAt = getTime();
var loadingTime = 0;
var timerInterval = setInterval(function() {