Skip to content

Instantly share code, notes, and snippets.

View janhesters's full-sized avatar
📈
Learning.

Jan Hesters janhesters

📈
Learning.
View GitHub Profile
@janhesters
janhesters / home-page-component.test.js
Created September 26, 2020 12:34
Tests for home page component.
import React from 'react';
import { describe } from 'riteway';
import render from 'riteway/render-component.js';
import HomePage from './home-page-component.js';
const createProps = ({ count = 0 } = {}) => ({ count });
describe('HomePage component', async assert => {
const createHomePage = (props = {}) => render(<HomePage {...props} />);
@janhesters
janhesters / home-page-component.js
Created September 26, 2020 12:33
Home page component skeleton.
import React, { Fragment } from 'react';
function HomePage() {
return <Fragment></Fragment>
}
export default HomePage;
@janhesters
janhesters / package.json
Created September 26, 2020 12:32
Package.json scripts.
"format": "echo 'Linting ...' && npm run -s lint --fix && echo 'Lint complete.'",
"lint": "eslint --ignore-path .gitignore .",
"test": "NODE_ENV=test riteway -r @babel/register 'src/**/*.test.js'",
"watch": "watch 'clear && npm run -s test | tap-nirvana && npm run -s format' src"
@janhesters
janhesters / .babelrc.json
Created September 26, 2020 12:31
Configure Babel.
{
"env": {
"test": {
"plugins": [
[
"module-resolver",
{
"root": [
"."
],
@janhesters
janhesters / .prettierrc.json
Created September 26, 2020 12:30
Configure Prettier
{
"arrowParens": "avoid",
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "always",
"quoteProps": "as-needed",
@janhesters
janhesters / .eslintrc.json
Created September 26, 2020 12:29
Configure ESLint.
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
@janhesters
janhesters / jsconfig.json
Created September 26, 2020 12:28
Absolute imports.
{
"compilerOptions": {
"baseUrl": "./src"
}
}
@janhesters
janhesters / selector-tests.js
Created September 26, 2020 08:57
Selector tests and setup with root reducer and actions array.
// root-reducer.js
const rootReducer = combineReducers({ /* ... */ });
const rootState = rootReducer(undefined, {});
export { rootReducer, rootState };
// in counter-reducer.test.js
import { rootReducer, rootState } from 'redux/root-reducer.js';
import { setOffset } from 'features/offset/offset-reducer.js';
@janhesters
janhesters / create-populated-state-usage.js
Created September 26, 2020 08:55
Setup with populated state factory function.
{
const summand = 1;
const state = createPopulatedState();
assert({
given: 'state with a count and an increment by action',
should: 'increment the count by the payload',
actual: reducer(state, incrementBy(summand)),
expected: createPopulatedState({ count: 42 /* , ... rest untouched */ }),
});
@janhesters
janhesters / exporting-initial-state-bad.js
Created September 26, 2020 08:49
Avoid exporting your initial state.
// 👇 Avoid exporting your initial state 🚫
export const initialState = {
wrongKey: 'foo',
correctKey: 'wrong value'
/* missing keys ... */
};
assert({
given: 'no arguments',
should: 'return the valid initial state',