Skip to content

Instantly share code, notes, and snippets.

View ricca509's full-sized avatar

Riccardo Coppola ricca509

View GitHub Profile
import { createElement, createContext, useReducer, useContext } from "react";
const Context = createContext();
export const ContextProvider = Context.Provider;
export const useStore = (reducer, initialState = {}) => {
const [state, dispatch] = useReducer(reducer, initialState);
const getState = () => state;
@ricca509
ricca509 / snapshot-serialisable-result.snap
Last active February 22, 2017 11:02
snapshot-serialisable-result.snap
exports[`Snapshot tests work with arrays 1`] = `
Array [
"a",
5,
[Function],
]
`;
exports[`Snapshot tests work with objects 1`] = `
Object {
@ricca509
ricca509 / snapshot-serialisable.js
Last active February 22, 2017 11:01
snapshot-serialisable.js
describe('Snapshot tests', () => {
it('work with objects', () => {
expect({
a: 234,
b: 'test',
c: null,
d: undefined,
}).toMatchSnapshot();
});
@ricca509
ricca509 / snapshot-result-snapshot.snap
Created February 21, 2017 09:54
snapshot-result-snapshot
exports[`The BuyNow component renders the right price and button 1`] = `
<div>
<span
className="price">
£
25
</span>
<button
className="btn-primary">
Buy now
@ricca509
ricca509 / snapshot-component-test-2.jsx
Created February 20, 2017 22:57
snapshot-component-test-2
// BuyNow.test.jsx
import { shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import BuyNow from '../BuyNow';
describe('The BuyNow component', () => {
it('renders the right price and button', () => {
const props = { price: 25, text: 'Buy now' };
const tree = shallow(<BuyNow {...props} />);
@ricca509
ricca509 / snapshot-component-test-1.jsx
Created February 20, 2017 22:56
snapshot-component-test-1
// BuyNow.jsx
const BuyNow = ({ price, text }) => (<div>
<span className="price">£{price}</span>
<button className="btn-primary">{text}</button>
</div>);
// BuyNow.test.jsx
import { shallow } from 'enzyme';
import BuyNow from '../BuyNow';
@ricca509
ricca509 / snapshot-api-handler.js
Created February 20, 2017 22:55
snapshot-api-handler
import handler from '../handler';
import expectedUserJson from '../mocks/user';
describe('the user handler', () => {
it('returns the user information given its id', () => {
const response = handler('35409DJFJ48');
expect(response).toEqual(expectedUserJson);
});
});
@ricca509
ricca509 / snapshot-function-test.js
Created February 20, 2017 22:54
snapshot-function-test
import { parseDate } from '..';
describe('parseDate', () => {
it('parses a Date object', () => {
const expectedResult = {
day: 13,
month: 2,
year: 2017
};
const result = parseDate(2017, 1, 13);
@ricca509
ricca509 / snapshot-function.js
Created February 20, 2017 22:53
snapshot-function
export function parseDate (date) {
return {
day: date.getDate(),
month: date.getMonth() + 1,
year: date.getFullYear()
};
}
const path = require('path');
const merge = require('webpack-merge');
const devConfig = require('./webpack.dev.config');
const prodConfig = require('./webpack.prod.config');
var config;
const common = {
entry: {