Skip to content

Instantly share code, notes, and snippets.

@johnnolan
johnnolan / 0_reuse_code.js
Created August 31, 2016 15:02
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
function funkyFun() {
var weGotTheFunk = 'gotta have that funk';
console.log('funkyFun');
console.log(weGotTheFunk);
return weGotTheFunk;
}
function hereBeDemons() {
console.warn('Just... be careful... please!');
console.error('uh oh');
return true;
}
function coolStory() {
var coolStoryBro = [
{ 'line': 'Now this is a story all about how' },
{ 'line': 'My life got flipped-turned upside down' },
{ 'line': 'And Id like to take a minute' },
{ 'line': 'Just sit right there' },
{ 'line': 'Ill tell you how I became the prince of a town called Bel-Air' }
];
function hammerTime() {
var cantTouchThis = true;
var myMusic = 'makes me so hard';
debugger;
if (myMusic === 'makes me so hard') {
return cantTouchThis;
} else {
return !cantTouchThis;
}
@johnnolan
johnnolan / setPropsInReduxEnzymemount.js
Last active February 11, 2019 09:19
If you want to test a Connected Component within a Provider while using Enzyme's mount and set its props to test how it renders by using something like toMatchSnapshot then you can set the props like so.
import React from "react";
import { mount } from 'enzyme';
import renderer from 'react-test-renderer'
import { Provider } from 'react-redux'
describe("Given you have a component that is wrapped in a Redux store and mount it, then you want to update the props of the child component", () => {
it('renders correctly', () => {
const mockStore = configureStore();
let store = mockStore(initialState)
let wrapper = mount(<Provider store={ store }><ConnectedComponent /></Provider>)
import React from "react";
import Button from "Button";
import { mountWrap } from 'contextWrap';
describe("Given the button is rendered with just a label", () => {
const data = {
label: "My Button"
}
let wrapper, aElement;
@johnnolan
johnnolan / JestReactHOC.js
Last active April 9, 2024 10:03
Example on how to test a React Higher Order Component using react-testing-library
import React from 'react'
import {render, cleanup} from 'react-testing-library'
// withHOC.js
function withHOC (WrappedComponent) {
render() {
return (
<main>
<section>
<h1>HOC Example</h1>

Keybase proof

I hereby claim:

  • I am johnnolan on github.
  • I am jb_moj (https://keybase.io/jb_moj) on keybase.
  • I have a public key ASCjbGsl86fHW4BRygZIlxzatF_SluEkb1xEyuuzq_asCAo

To claim this, I am signing this object:

@johnnolan
johnnolan / example-response.json
Created March 8, 2021 09:04
Performance Platform API
[
{
"_id": "MjAyMC0wNi0wMVQwMDowMDowMCswMDowMG9wZy11c2UtYW4tbHBhbW9udGh0cmFuc2FjdGlvbnNkaWdpdGFs",
"_timestamp": "2020-06-01T00:00:00+00:00",
"service": "opg-use-an-lpa",
"channel": "digital",
"count": 456,
"dataType": "transactions",
"period": "month"
},