Skip to content

Instantly share code, notes, and snippets.

const { mount, getWrapper } = createTestContext({
fixture: {
component: Users,
fetch: [{
matcher: '/users',
response: ['Mary', 'Jason']
}]
}
});
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');
});
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')
@ovidiuch
ovidiuch / rename.js
Last active July 8, 2022 21:45
Rename camelCase files to kebab-files
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();
@ovidiuch
ovidiuch / test.js
Created May 25, 2017 07:56
Enzyme mount() vs shallow() for component context providers
import React, { Component, PropTypes } from 'react';
import { shallow, mount } from 'enzyme';
class ContextProvider extends Component {
getChildContext() {
return {
foo: 'bar'
};
}
@ovidiuch
ovidiuch / backdiff.sh
Created January 26, 2017 12:07
Quickly back up git diff without committing work in progress
git diff HEAD > myprecious.patch
mv myprecious.patch ~/Desktop # auto backed on iCloud
index.html
+ var domContainer = document.getElementById('content');
+ var rootComponent = Boards.render(getFixtureContents(), domContainer);
+ Boards.onRouteChange(function(props) {
+ rootComponent = Boards.render(props, domContainer);
+ });
boards.js
@ovidiuch
ovidiuch / gist:5850621
Last active December 18, 2015 21:58
Calculate percentages of loading time improvement
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],
@ovidiuch
ovidiuch / gist:5850424
Created June 24, 2013 14:24
Benchmarking the loading time of app.ubervu.com, behind the scenes of the Loading Animation
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() {
@ovidiuch
ovidiuch / gist:5066247
Created March 1, 2013 17:24
Rethink Mozaic.newDataChannels
# Refactoring the way "newDataChannels" works, maybe with an alternative
# (temporary) "createChannels" method
# With current method:
[facebook_ad_accounts,
facebook_campaigns,
facebook_ads] = Utils.newDataChannels(
'/facebook-ad-accounts': {}
'/facebook-campaigns': {}