Skip to content

Instantly share code, notes, and snippets.

import api from './api';
export function addPhotos() { /* ... */ }
export function fetchPhotos() {
return async function(dispatch) {
const { data: photos } = await api.fetchPhotos();
dispatch(addPhotos(photos));
};
}
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import * as actions from '../../actions/TodoActions'
import * as types from '../../constants/ActionTypes'
import fetchMock from 'fetch-mock'
import expect from 'expect' // You can use any testing library
const middlewares = [thunk]
const mockStore = configureMockStore(middlewares)
import { mount } from 'enzyme';
import { PhotosContextInner } from './PhotosContext';
describe('PhotosContext', () => {
test('fetchPhotos', async () => {
const api = {
fetchPhotos: () => ({ data: [{ caption: 'photo caption', src: 'src' }] }),
};
@tfiechowski
tfiechowski / cluster-script.js
Created January 17, 2019 09:27
NodeJS script running in cluster
const { spawn } = require("child_process");
const fs = require("fs");
const cluster = require("cluster");
const numCPUs = require("os").cpus().length;
const scriptFile = './script.sh';
let tasks = [];
function runScript(arg) {
import React, { createContext } from "react";
const AuthContext = createContext({});
const { Consumer, Provider } = AuthContext;
export class AuthContextProvider extends React.Component {
constructor(props) {
super(props);
@tfiechowski
tfiechowski / rspec.rb
Created April 10, 2019 08:08
Sample RSpec unit test
class HelloWorld
def say_hello
"Hello World!"
end
end
describe HelloWorld do
context “When testing the HelloWorld class” do
{
"name": "react-sample-components-library",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
module.exports = {
webpackConfig: {
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: "babel-loader"
}
]
module.exports = {
webpackConfig: {
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: "babel-loader"
}
]