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 17, 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

View selectors.md

Overview

There are three type of selectors:

  • basic
  • cached
  • cached factory
// Basic
const selectUsers = state => get(state, '_entites.users');
@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");
View mock_implementation.js
test("mock implementation", () => {
const mock = jest.fn(() => "bar");
expect(mock("foo")).toBe("bar");
expect(mock).toHaveBeenCalledWith("foo");
});
test("also mock implementation", () => {
const mock = jest.fn().mockImplementation(() => "bar");
@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 / 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);
});
@rickhanlonii
rickhanlonii / mock_basic.js
Last active Feb 20, 2019
Mock Function Basic
View mock_basic.js
test("returns undefined by default", () => {
const mock = jest.fn();
let result = mock("foo");
expect(result).toBeUndefined();
expect(mock).toHaveBeenCalled();
expect(mock).toHaveBeenCalledTimes(1);
expect(mock).toHaveBeenCalledWith("foo");
});
@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_dep_injection.js
Last active Mar 4, 2018
Mock Dependency Injection
View mock_dep_injection.js
const doAdd = (a, b, callback) => {
callback(a + b);
};
test("calls callback with arguments added", () => {
const mockCallback = jest.fn();
doAdd(1, 2, mockCallback);
expect(mockCallback).toHaveBeenCalledWith(3);
});