Skip to content

Instantly share code, notes, and snippets.

Avatar
🖤
Black Lives Matter

Ricky rickhanlonii

🖤
Black Lives Matter
View GitHub Profile
@rickhanlonii
rickhanlonii / react_18_working_group_q_a.md
Last active Jun 16, 2021
React 18 Working Group Q&A
View react_18_working_group_q_a.md

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 Mar 8, 2018
Mock Test with jest.spyOn sugar
View mock_jest_spyOn_sugar.js
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 Dec 22, 2020
Mock Test with jest.spyOn and mockRestore
View mock_jest_spyOn_restore.test.js
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 Feb 20, 2019
Mock Test with jest.spyOn
View mock_jest_spyOn.test.js
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 Feb 20, 2019
Mock Test with jest.mock
View mock_jest_mock.test.js
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 Mar 4, 2018
Mock jest.fn example
View math.eg.js
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 Feb 20, 2019
Mock Test with jest.fn
View mock_jest_fn.test.js
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);
});
View 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);
View 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;
View mock_project.md
├ example/
| └── app.js
| └── app.test.js
| └── math.js