Skip to content

Instantly share code, notes, and snippets.

View rickhanlonii's full-sized avatar
git push -f

Ricky rickhanlonii

git push -f
View GitHub Profile
@rickhanlonii
rickhanlonii / react_18_working_group_q_a.md
Last active June 17, 2021 11:35
React 18 Working Group Q&A

Andrew: So, yes, my name is Andrew, I'm the React atom floating. Next time I think we'll make it so I have two phones so I can join from my account. Oh, there's Dan, let me add Dan. So this is our first time hosting a space. Well, I've done one before, but nothing like this. I have a feeling there's going to be a lot more people on this space than the silly spaces I've hosted before. So we might learn as we go along, but we we've gotten some great advice from some folks ahead of time the proper way to manage these things, including from Laurie, who I think we'll hear from later. So I think this is going to be really great. Hopefully the first of many.

Andrew: Let's just give it a few minutes for people to trickle in. I'm sure we'll have additional guests as we go along. Brian is giving us a reminder: if we do invite you on stage to please mute yourself when you're not speaking, I will do the same. We've got some great questions that we've collected in advance from members of the working group. And if you do

@rickhanlonii
rickhanlonii / mock_jest_spyOn_sugar.js
Last active March 8, 2018 16:41
Mock Test with jest.spyOn sugar
import * as app from "./app";
import * as math from "./math";
test("calls math.add", () => {
// store the original implementation
const originalAdd = math.add;
// mock add with the original implementation
math.add = jest.fn(originalAdd);
@rickhanlonii
rickhanlonii / mock_jest_spyOn_restore.test.js
Last active December 22, 2020 14:24
Mock Test with jest.spyOn and mockRestore
import * as app from "./app";
import * as math from "./math";
test("calls math.add", () => {
const addMock = jest.spyOn(math, "add");
// override the implementation
addMock.mockImplementation(() => "mock");
expect(app.doAdd(1, 2)).toEqual("mock");
@rickhanlonii
rickhanlonii / mock_jest_spyOn.test.js
Last active February 20, 2019 11:40
Mock Test with jest.spyOn
import * as app from "./app";
import * as math from "./math";
test("calls math.add", () => {
const addMock = jest.spyOn(math, "add");
// calls the original implementation
expect(app.doAdd(1, 2)).toEqual(3);
// and the spy stores the calls to add
@rickhanlonii
rickhanlonii / mock_jest_mock.test.js
Last active February 20, 2019 11:40
Mock Test with jest.mock
import * as app from "./app";
import * as math from "./math";
// Set all module functions to jest.fn
jest.mock("./math.js");
test("calls math.add", () => {
app.doAdd(1, 2);
expect(math.add).toHaveBeenCalledWith(1, 2);
});
@rickhanlonii
rickhanlonii / math.eg.js
Created March 4, 2018 18:31
Mock jest.fn example
export const add = jest.fn();
export const subtract = jest.fn();
export const multiply = jest.fn();
export const divide = jest.fn();
@rickhanlonii
rickhanlonii / mock_jest_fn.test.js
Last active February 20, 2019 11:40
Mock Test with jest.fn
import * as app from "./app";
import * as math from "./math";
math.add = jest.fn();
math.subtract = jest.fn();
test("calls math.add", () => {
app.doAdd(1, 2);
expect(math.add).toHaveBeenCalledWith(1, 2);
});
@rickhanlonii
rickhanlonii / app.js
Created March 4, 2018 18:22
Mock app.js
import * as math from './math.js';
export const doAdd = (a, b) => math.add(a, b);
export const doSubtract = (a, b) => math.subtract(a, b);
export const doMultiply = (a, b) => math.multiply(a, b);
export const doDivide = (a, b) => math.divide(a, b);
@rickhanlonii
rickhanlonii / math.js
Created March 4, 2018 18:21
Mock math.js
export const add = (a, b) => a + b;
export const subtract = (a, b) => b - a;
export const multiply = (a, b) => a * b;
export const divide = (a, b) => b / a;
@rickhanlonii
rickhanlonii / mock_project.md
Last active March 4, 2018 18:20
Mock Project
├ example/
| └── app.js
| └── app.test.js
| └── math.js