Skip to content

Instantly share code, notes, and snippets.

View OlaoluwaM's full-sized avatar
🧠
Always learning

Olaoluwa Mustapha OlaoluwaM

🧠
Always learning
View GitHub Profile
@OlaoluwaM
OlaoluwaM / act-example.js
Last active October 4, 2020 23:14
act example snipper
test('should do.....', () => {
/*Rest of the test*/
act(() => {
// Event will cause state update and rerender in controlled input component
fireEvent.input(inputElement, {target: {value: '123'}})
// 'act' will make sure updates are applied to the DOM
})
// So our assertion work with with updated UI
@OlaoluwaM
OlaoluwaM / async-test-example.js
Last active October 4, 2020 23:16
async test example
test('should...', async () => {
await act(async () => {
fireEvent.input(inputElement, {target: {value: 123}})
})
})
@OlaoluwaM
OlaoluwaM / async-test-example-with-act.js
Created October 4, 2020 23:18
Async test example with act function
test('should let user know their input was invalid or incorrect', async () => {
const {findByPlaceholderText, findByTestId} = render(<AuthComp />) // Or whatever you call you authentication component
const inputElement = await findByPlaceholderText('Age') // any query function prefixed with findBy* is asynchronous
await act(async () => {
fireEvent.input(inputElement, {target: {value: 12}})
})
const validationErrorElement = await findByTestId('validation-error');
@OlaoluwaM
OlaoluwaM / react-toastify-test-example.js
Last active October 7, 2020 23:48
React Toastify test snippet example
jest.useFakeTimers()
test('should inform user of task completion', () => {
const { getByRole } = render(<App />)
jest.advanceTimersByTime(1000); // You can vary the time depending on how long you have set the toast in question to be visible for
const toast = getByRole('alert') // Toasts generated by the library have a role of alert
expect(toast).toBeInTheDocument();
})
@OlaoluwaM
OlaoluwaM / depVersionUpdate.mjs
Last active May 12, 2021 09:09
A script that auto updates dependencies defined in your template.json file for those who have custom CRA templates
#!/usr/bin/env node
import fsPromise from 'fs/promises';
import { exec } from 'child_process';
import { promisify } from 'util';
const promisifiedExec = promisify(exec);
const normalize = str => (str === '' ? false : true);
@OlaoluwaM
OlaoluwaM / Example.tsx
Created August 14, 2021 09:49 — forked from stolinski/Example.tsx
Route Transitions with Framer Motion
const FakeComponent = () => {
return (
<AnimatedRoutes exitBeforeEnter initial={false}>
<RouteTransition exact path="/some-route">
<NewUsers />
</RouteTransition>
<RouteTransition exact path="/yo" >
<Users />
</RouteTransition>
</AnimatedRoutes>
@OlaoluwaM
OlaoluwaM / kitty.conf
Created January 25, 2022 17:55 — forked from sts10/kitty.conf
My config file for Kitty Terminal Emulator
# vim:fileencoding=utf-8:ft=conf:foldmethod=marker
#: Fonts {{{
#: kitty has very powerful font management. You can configure
#: individual font faces and even specify special fonts for particular
#: characters.
font_family JetBrains Mono Medium
bold_font JetBrains Mono Bold
@OlaoluwaM
OlaoluwaM / grokking_to_leetcode.md
Last active May 16, 2022 09:48 — forked from tykurtz/grokking_to_leetcode.md
Grokking the coding interview equivalent leetcode problems

GROKKING NOTES

I liked the way Grokking the coding interview organized problems into learnable patterns. However, the course is expensive and the majority of the time the problems are copy-pasted from leetcode. As the explanations on leetcode are usually just as good, the course really boils down to being a glorified curated list of leetcode problems.

So below I made a list of leetcode problems that are as close to grokking problems as possible.

Pattern: Sliding Window

@OlaoluwaM
OlaoluwaM / The Rules.md
Created April 20, 2022 07:05 — forked from sebmarkbage/The Rules.md
The Rules of React

The Rules of React

All libraries have subtle rules that you have to follow for them to work well. Often these are implied and undocumented rules that you have to learn as you go. This is an attempt to document the rules of React renders. Ideally a type system could enforce it.

What Functions Are "Pure"?

A number of methods in React are assumed to be "pure".

On classes that's the constructor, getDerivedStateFromProps, shouldComponentUpdate and render.

@OlaoluwaM
OlaoluwaM / README-Fancy.md
Created May 29, 2022 05:57 — forked from ramantehlan/README-Fancy.md
README template I use for most of my projects.

Introduction

  • Add your project logo.
  • Write a short introduction to the project.
  • If you are using badges, add them here.

📒 Index